docker-compose docker compose basics / troubleshooting:

docker-compose docker compose basics / troubleshooting:
Photo by Ian Taylor / Unsplash

Typically one can follow this guide to install their docker. Which recomends the following script:

# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg

# Add the repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update

Put it inside a file with:


And then make executable with:

chmod +x && ./

Once we have this done we need to test that we have a working docker environment:

mkdir helloword && cd helloworld
nano docker-compose.yml

Inside it put:

version: '2'
    image: ubuntu
    command: [/bin/echo, 'Hello world']

Understanding docker-compose / docker compose:

  • docker-compose may not work but docker compose will or vice versa.
  • docker compose builds images.. or effectively works with docker-compose.yml files.
  • docker run then activates those images into a running container.

Build your image with:

docker-compose -f docker-compose.yml build

One can do only a pull for the associate images.

docker-compose -f docker-compose.yml pull

And then it can be run with:

docker-compose -f docker-compose.yml up -d
  • What is strange is -d must be after the up.

One can inspect the built image with:

docker image ls

The difference between DockerFile and docker-compose.yml:

Is easily and best described as:

Dockerfile - commands for a single container

docker-compose.yml instructions for multiple images and containers.

One can then run an image with:

docker run --name bob ubuntu:latest

One can then list running containers with:

docker ps -a

And stop (and remove) them with

docker stop bob
docker rm bob

Finally if the container is deleted the underlying images can also be deleted by:

docker image prune --all
Linux Rocks Every Day