Docker

December 7, 2019 DevOps 1 minute, 43 seconds

After starting a service via docker-compose Docker will shut it down if there is no process running. To prevent that you can call a "dummy" endless command - in this case by overriding the entrypoint with a simple ping.

entrypoint: ping localhost

The btrfs storage driver of Docker is kind of different. A normal df -hkl /var/lib/docker will not show correct numers. Instead use the tools of btrfs:

btrfs fi df /varLib/docker

vim /etc/systemd/system/multi-user.target.wants/docker.service (adjust for other startup mechanism)

[Service]
Environment="HTTPS_PROXY=https://proxy.example.com:443/"

docker build --build-arg HTTP_PROXY=proxy.company.com:3128 -t TAG .

docker exec CONTAINER sh -c "cat /tmp/test"

version: "3.0"
services:
  alpine:
    image: alpine
    volumes:
      - /tmp/:/tmp/
    tty: true

Starting the service with docker-compose up -dkeeps the container running

DOCKER_HOST=tcp://192.168.56.101:2375
# with TLS enabled Daemon
# make sure that ~/.docker/ of the current user contains the ca.pem or the {cert,key}.pem in case of client auth
export DOCKER_TLS_VERIFY=1

Set the timestamp of your configuration in the Dockerfile file to zero

RUN         touch -d @0 /config.yml

In your entrypoint check the timestamp. When the timestamp is zero the container is started for the first time

if [ "$(stat --format %Y /config.yml)" -eq 0 ]; then
# initial start of the container
fi

/etc/systemd/system/NAME.service

[Unit]
Description=Start Container
After=docker.service
Requires=docker.service

[Service]
Restart=always
ExecStart=/usr/bin/docker start -a CONTAINER
ExecStop=/usr/bin/docker stop -t 5 CONTAINER

[Install]
WantedBy=multi-user.target

Start und enable service at boot time

systemctl start NAME
systemctl enable NAME

docker commit CONTAINERID test
docker run -it --entrypoint=/bin/bash test