Docker Way

Tagging Images

  • Image tags are not discrete copies of a file.

  • The same image can have multiple tags on on your system.

Tagging docker images
$ docker tag baku:latest gnomon/baku:1.0
$ docker tag baku:latest gnomon/baku:latest
$ docker images | grep cee3ab3df0c0
gnomon/baku-docker 1.0     cee3ab3df0c0   8 weeks ago    259MB
gnomon/baku-docker latest  cee3ab3df0c0   8 weeks ago    259MB
baku               latest  cee3ab3df0c0   8 weeks ago    259MB
  • Note how all three tags…

    • baku:latest for local use as “latest”

    • gnomon/baku-docker:1.0 for pushing to Docker hub as “1.0”

    • gnomon/baku-docker:latest for pushing to Docker hub as “latest”

  • …all have the same image-id, cee3ab3df0c0.

  • Pushing to Docker Hub is easy with…

docker push gnomon/baku-docker:1.0
docker push gnomon/baku-docker:latest

Specifying alternate registries

  • Docker hub is not the only possible registry.

  • Self-hosted registries, such as Nexus [1] and AWS ECR [2] are common.

  • Using the example of an AWS ECR registry in account 111222333, we can push our Baku container there.

Push image to ECR
docker tag baku:latest \
  111222333.dkr.ecr.us-east-1.amazonaws.com/baku:1.0
docker push 111222333.dkr.ecr.us-east-1.amazonaws.com/baku:1.0

Start Scripts

Systemd unit files

Docker run

  • Assuming…

    • a containerized application called myapp

    • a service user called svc.myapp

    • myapp files in /data/docker/myapp

    • a port map of local 80 to the container’s 8080

    • a drive map of /data/docker/myapp to /data in the container

Unit file for a docker run example
 1[Unit]
 2Documentation=https://docs.docker.com
 3After=docker.service
 4Requires=docker.service
 5
 6[Service]
 7User=svc.myapp
 8Group=docker
 9RemainAfterExit=true
10StandardOutput=journal
11WorkingDirectory=/data/docker/myapp
12ExecStart=/usr/bin/docker run --rm --name=myapp -p80:8080 -v /data/docker/myapp:/data
13ExecStop=/usr/bin/docker stop myapp
14
15[Install]
16WantedBy=multi-user.target

Docker compose plugin

  • The legacy docker-compose binary is deprecated.

  • Docker now has a plugin executed with docker compose [3].

  • Assuming…

    • a containerized application called myapp

    • a service user called svc.myapp

    • myapp files in /data/docker/myapp

    • Docker Compose YAML in /data/docker/myapp/docker-compose.yml

Unit file for a docker compose example
 1[Unit]
 2Description=Container for myapp
 3Documentation=https://docs.docker.com
 4After=docker.service
 5Requires=docker.service
 6
 7[Service]
 8Type=oneshot
 9User=svc.myapp
10Group=docker
11RemainAfterExit=true
12StandardOutput=journal
13WorkingDirectory=/data/docker/myapp
14#Replace the "docker compose" with "docker-compose" for legacy builds
15#ExecStart=/bin/docker-compose up -d --remove-orphans
16#ExecStop=/bin/docker-compose down
17ExecStart=/bin/docker compose up -d --remove-orphans
18ExecStop=/bin/docker compose down
19
20[Install]
21WantedBy=multi-user.target