With Docker and Docker-Compose installed, we can spin up some containers. The procedure is fairly straightforward and will be the same for the majority of containers with the exception of more advanced containers.

For this example, I will be creating a Dozzle container. Dozzle is a web interface for realtime Docker logs. This is extremely useful for troubleshooting. Dozzle is not a necessity for retrieving container logs, but it is a game-changer when it comes to getting quick answers for troubleshooting purposes.


Creating Docker Network

I prefer to put all my containers that are somewhat related on the same Docker network. This is incredibly useful for reverse proxies, such as Traefik or Nginx Proxy Manager. For that purpose, I will create a Docker network using the following command.

sudo docker network create proxy

I’m naming the network proxy because I’ll be setting up a reverse proxy in a future tutorial. It doesn’t matter what you name it as long as you modify the yaml files I provide.


Basic Docker-Compose File Structure

As mentioned before, with Docker-Compose we will need a yml file that contains the container configuration. I typically use the following structure with my containers.

.
└── ~/docker/
    ├── <container_1_name>/
    │   └── docker-compose.yml
    ├── <container_2_name>/
    │   └── docker-compose.yml
    └── <container_n_name>/
        └── docker-compose.yml

For Dozzle, I will use the following.

.
└── ~/docker/
    └── dozzle/
        └── docker-compose.yml

Creating The Configuration File

We can create the directories and set the current working directory to that same folder using the following commands.

mkdir -p ~/docker/dozzle
cd ~/docker/dozzle

Now we need to create a docker-compose.yml file. Most Linux distros come with vim and/or nano by default. I like vim more, so I will use that to create and edit the file.

vim docker-compose.yml

Paste the following content then save the file. If you don’t know how to exit vim, first hit the escape key followed by :wq then enter to write and quit.

 1services:
 2  dozzle:
 3    container_name: dozzle
 4    networks:
 5      - proxy
 6    image: amir20/dozzle:latest
 7    restart: unless-stopped
 8    volumes:
 9      - /var/run/docker.sock:/var/run/docker.sock
10    ports:
11      - 9999:8080
12
13networks:
14  proxy: # remember to change this if necessary
15    external: true 

This specifies that we want to pull the latest Dozzle image off the hub and put it on port 9999. We are telling it that we want it to continue to restart unless we tell Docker that we want the container to stop, even after rebooting. The port doesn’t matter as long as it isn’t yet in use.

If you want to change the port, modify the port to the left of the colon. Do not modify the one of the right of the colon. In a future tutorial, we will eliminate the need to expose ports using a reverse proxy.

Spinning Up The Container

With all that out of the way, all we need to do is start the container.

sudo docker-compose up -d

This tells Docker-Compose that we want it to spin up the container in detached mode. This means it’ll be a background process. To access it, you can navigate to <server ip>:<exposed port>> in your browser, and you’ll be presented with the Dozzle dashboard.

For instance: 10.0.1.64:9999


Stopping The Container

If you want to stop the container:

sudo docker-compose down

Summary

We created a docker-compose.yml file and spun up a container using the configuration file. Hopefully you have a better understanding of the power and potential of Docker and how it can be used.