Installing Docker
Starting
Maybe you have never used docker before, I did (ofcourse). But each time I use it again, I have to lookup how to exactly install it, because there are some commands. Personally I always use docker-compose, why? Because I never need the regular docker. This post will also be my new guide, as I normally use a link from my bookmarks. For this whole post I'm going to assume you have sudo rights.
Do note, the link above is updated, my website is not. So use it at your own risk.
Downloading and installing
This guide is only for ubuntu, as the installation for the other distro's slightly differ.
Go ahead and login to your container/vm, and paste the following commands:
apt update
apt install ca-certificates curl
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
chmod a+r /etc/apt/keyrings/docker.asc
Don't get scared, the > marks are supposed to be there, and will dissapear.
Then make sure you update the system by using: Now, install the packages
Starting up docker
Docker should automatically start up, but to make sure it has started you can check, and start with the following commands:
If you really want to make sure the installation has succeeded. This will download a test image and runs a test container, when it prints the confirmation, it will automatically stop itself.Setting up a container/service
The following instructions will differ from your use case, but below I will start a homepage container. Create a folder for you docker container, and create the docker-compose.yml:
I have posted the basic config from the homepage documentation:- The 'image:', is where docker pulls the software from. This should be the link to the repository.
- The 'container_name', is the name, your container gets. As simple as that.
- The 'ports:' section, is where you assign ports to your container. The left part '8080', is the port you assign to your network, to reach the container. Inside the container, the right part '3000', is the port the service listens to. The port outside your container, can be anything you want.
- The 'volumes:' section, is where you assign your directories to, again, the left side is outside of the container, the right side is for the service itself.
- The 'environment:' section, is where you set settings, as in this example the domain name of the site. Its also common to create a seperate variables file, I will dive into that in the next part.
Environment
If you have a lot of environment settings, it might be usefull to put them in a seperate file. This will tidy up the configuration file. Go ahead and create the environment file:
The file will look like the following, ofcourse, change to your own settings (this example is from my owncloud):As you can see, I have more environment settings in the configuration, then in the env file. Don't ask me why, but that's apparently the way I did it when I installed this container
Starting a container
To start up the container you created, use the following command in the directory your docker-compose.yml file is located:
Status Docker-compose
With the following command you can see the status of the container:
And the expected output for my container:root@Homepage:~/homepage# docker compose ps
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
homepage ghcr.io/gethomepage/homepage:latest "docker-entrypoint.s…" homepage 3 months ago Up 3 months (healthy) 0.0.0.0:3001->3000/tcp, [::]:3001->3000/tcp
Status Docker
With the following command you can see the status of all the containers:
And the expected output for my container:root@Homepage:~/homepage# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b24d77f01178 ghcr.io/gethomepage/homepage:latest "docker-entrypoint.s…" 3 months ago Up 3 months (healthy) 0.0.0.0:3001->3000/tcp, [::]:3001->3000/tcp homepage
I hope that was enough explanation to get you started with docker compose.