Docker Way ########## Tagging Images ============== * Image tags are not discrete copies of a file. * The same image can have multiple tags on on your system. .. code-block:: :caption: 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... .. code-block:: bash 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 [#]_ and AWS ECR [#]_ are common. * Using the example of an AWS ECR registry in account **111222333**, we can push our Baku container there. .. code-block:: plain :caption: 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 .. .. [#] https://www.sonatype.com/products/sonatype-nexus-oss-download .. [#] https://aws.amazon.com/ecr/ 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 .. code-block:: bash :caption: Unit file for a docker run example :linenos: [Unit] Documentation=https://docs.docker.com After=docker.service Requires=docker.service [Service] User=svc.myapp Group=docker RemainAfterExit=true StandardOutput=journal WorkingDirectory=/data/docker/myapp ExecStart=/usr/bin/docker run --rm --name=myapp -p80:8080 -v /data/docker/myapp:/data ExecStop=/usr/bin/docker stop myapp [Install] WantedBy=multi-user.target .. Docker compose plugin ^^^^^^^^^^^^^^^^^^^^^ * The legacy `docker-compose` binary is deprecated. * Docker now has a plugin executed with `docker compose` [#]_. * 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* .. code-block:: bash :caption: Unit file for a docker compose example :linenos: [Unit] Description=Container for myapp Documentation=https://docs.docker.com After=docker.service Requires=docker.service [Service] Type=oneshot User=svc.myapp Group=docker RemainAfterExit=true StandardOutput=journal WorkingDirectory=/data/docker/myapp #Replace the "docker compose" with "docker-compose" for legacy builds #ExecStart=/bin/docker-compose up -d --remove-orphans #ExecStop=/bin/docker-compose down ExecStart=/bin/docker compose up -d --remove-orphans ExecStop=/bin/docker compose down [Install] WantedBy=multi-user.target .. .. [#] https://docs.docker.com/compose/install/linux/