This is an old revision of the document!


Docker

Install

Ubuntu:

curl -sSL https://get.docker.com | sh

SLES:

zypper se -s docker                          #get the version
zypper in -f docker=18.06.1_ce-98.21.1       #reference the version 

Control service:

systemctl is-enabled docker.service
systemctl start docker.service
systemctl status docker.service
systemctl daemon-reload
systemctl restart docker
systemctl show --property Environment docker

Commands

Container

Start, stop, manage containers:

docker container ls
docker container ls --all
docker container start 10095cc1e53d
docker start 176bd91300c3                                                           #Start Container
docker container stop 00b9227af244
docker container rm b9e0eb78c272
docker rm $(docker ps --all -q -f status=exited)
docker rename CONTAINER_NAME NEW_NAME                                               #Rename container
docker commit my-container ubuntu:16.04                                             #Commit changes from container "my-container" to image "ubuntu:16.04"
docker stats redis1 redis2                                                          #command to live stream a container’s runtime metrics (cpu, mem etc.)

Forcefully delete all containers, so pay attention!!

docker container rm $(docker container ls -a -q)

Image

docker image ls
docker images -q                                                                    #Just show "IMAGE ID"
docker images --digests                                                             #show "sha" value to get version of e. g. "lastest"
docker image ls --all
docker pull mysql/mysql-server:latest                                               #Install image mysql

Forcefully delete all images, so pay attention!!

docker rmi $(docker images -q) -f 

Save & Restore

docker image save 915f54b28a31 -o ubuntu-16.04.tar
docker image import ubuntu-16.04.tar ubuntu-16.04
docker exec some-mysql sh -c 'exec mysqldump --all-databases -uroot -p"$MYSQL_ROOT_PASSWORD"' > /some/path/on/your/host/all-databases.sql                   

Build

docker build -t "simple_flask:dockerfile" .                                         #Build an image from a Dockerfile
docker build - < Dockerfile
docker build -t friendlyhello .                                                     #Create image using this directory's Dockerfile
docker build -t friendlyhello /usr/lib/docker/example/.                             #Create image using path Dockerfile
docker build -t ubuntu16-test:16.04 --no-cache .
docker history simple_flask:dockerfile
docker build -t ubuntu16-squid:16.04 /software/.                                    #Build image "ubuntu16-squid" from Dockerfile within "/software/"
docker build --build-arg http_proxy=http://1.2.3.4:80 --build-arg https_proxy=http://1.2.3.4:80 -t ubuntu16-squid:16.04 .
 

Deploy Container

docker run ubuntu:16.04                                                             #Download ans install ubuntu 16.04
docker run --name=mysql-01 -d mysql/mysql-server:latest
docker run --name=mysql-01 -d mysql/mysql-server:latest
docker run --name=ubuntu16.04-squid-1 ubuntu:16.04
docker run -d -p 8080:8080 --name=ubuntu16.04-squid-2 -ti ubuntu:16.04              #Deploy and keep running container from image "ubuntu:16.04"
docker run --name=mysql01 -d mysql:dockerfile
docker run -d -p 3306:3306 -v /path/in/host:/var/lib/mysql dordoka/rpi-mysql
docker run -d -p 3306:3306 --name=mysql01 -v /path/in/host:/var/lib/mysql -d mysql/mysql-server:latest
docker run --name=test-kibana -d rutsky/kibana-logtrail-kubernetes:4.6.1-0.1.7-2
docker run -p 8080:80 -p 8443:443 68b57f0b6302 apache2-foreground

Run

Run and connect to container. When exiting, container stopps!

docker run -ti ubuntu:latest /bin/bash
docker run -ti ubuntu /bin/bash
docker run -ti mysql:dockerfile
docker run -d -p 3306:3306 mysql:dockerfile

Info

docker version
docker info
docker logs mysql01
journalctl -fu docker
docker ps
docker ps --all
docker inspect f8f1140788d8

Connect

Connect to running (!) container:

docker exec -it mysql3 bash
docker exec -it 7079297b1b01 /bin/bash
docker exec -it 4c1d592d40d9 mysql -uroot -p
docker exec -it 176bd91300c3 bash

Volumes

docker volume create --label DataVolume1
docker volume create -d netapp --name myFirstVolume -opt size=1G
docker volume inspect DataVolume1
docker run -d \
  --name=nginxtest \
  -v nginx-vol:/usr/share/nginx/html:ro \
  nginx:latest
 
docker run -d \
  --name=nginxtest \
  --mount source=nginx-vol,destination=/usr/share/nginx/html,readonly \
  nginx:latest
docker run -ti --name=Container2 -v DataVolume2:/datavolume2 ubuntu
docker run -ti --name=Container2 -v DataVolume1:/datavolume1 ubuntu
docker run --rm -ti -v DataVolume1:/datavolume1 ubuntu

Plugin

docker plugin ls
docker plugin install netapp/trident-plugin:18.04 --alias netapp --grant-all-permissions

Path

/usr/lib/docker/
/var/lib/docker/

User

Use docker by a user that is a member of the docker group. If you do not have a user in that group, issue the command

sudo usermod -a -G docker USERNAME

Dockerfile

Squid

https://docs.docker.com/engine/reference/builder/

Example dockerfile which builds ubuntu 16.04 with compiled squid 4.8:

Dockerfile
#Download base image ubuntu 16.04
FROM ubuntu:16.04
LABEL version="1.0"
LABEL maintainer="Thomas Roehm"
 
ENV SQUID_VERSION="4.8"
ENV SQUIDURL="http://www.squid-cache.org/Versions/v4/squid-${SQUID_VERSION}.tar.gz"
#ENV https_proxy "http://my-proxy:80"
#ENV http_proxy "http://my-proxy:80"
#ENV no_proxy "localhost,127.0.0.1,myhost.local"
 
# locales to UTF-8
#RUN locale-gen C.UTF-8 && /usr/sbin/update-locale LANG=C.UTF-8
#ENV LC_ALL C.UTF-8
#ENV SQUID_VERSION=3.5.12-1ubuntu7
#SQUID_CACHE_DIR=/var/spool/squid
#SQUID_LOG_DIR=/var/log/squid
#SQUID_USER=proxy
 
RUN apt-get update
RUN apt-get -y upgrade
#RUN apt-get -y dist-upgrade
#RUN DEBIAN_FRONTEND=noninteractive
RUN apt-get install -y build-essential
RUN apt-get install -y net-tools
RUN apt-get install -y wget
RUN apt-get install -y libssl-dev
RUN apt-get install -y telnet
RUN apt-get install -y vim
RUN apt-get -qy autoremove
#RUN rm -rf /var/lib/apt/lists/*
 
#WORKDIR /data/
RUN wget ${SQUIDURL}
RUN tar -xzf squid-${SQUID_VERSION}.tar.gz
RUN cd /squid-${SQUID_VERSION} && ./configure --with-large-files --enable-follow-x-forwarded-for --sysconfdir=/etc/squid --localstatedir=/var/log/squid --enable-ssl --with-openssl --with-filedescriptors=16384 --enable-storeio=diskd,ufs --prefix=/usr/local/squid --with-included-ltdl
RUN cd /squid-${SQUID_VERSION} && make && make install
RUN useradd -r squid -s /bin/false
RUN cat /etc/passwd
#RUN groupadd -r squid
RUN touch /var/log/squid/logs/access.log
RUN cd /var/log/squid/ && chmod -R 770 * && chown -R squid:squid *
RUN chmod 640 /var/log/squid/logs/access.log
 
#COPY entrypoint.sh /test/entrypoint.sh
#RUN chmod 750 /test/entrypoint.sh
 
COPY squid-init /etc/init.d/squid
RUN chmod 750 /etc/init.d/squid
COPY squid.conf /etc/squid/squid.conf
#CMD "./entrypoint.sh"
#ENTRYPOINT ["/usr/local/squid/sbin/squid", ]
#CMD ["-z"]
ENTRYPOINT /usr/local/squid/sbin/squid -z && sleep 10 && /etc/init.d/squid start && echo "Squid started" || echo "Squid could not start, exit" && bash
#CMD ["--help"]
 
 
#ENTRYPOINT "/sbin/entrypoint.sh && /bin/bash"
 
 
#EXPOSE 8080/tcp
#CMD ["/usr/local/squid/sbin/squid -z"]
#ENTRYPOINT ["/etc/init.d/squid","start"]
#CMD ["/bin/bash", "/usr/local/bin/start.sh"]
#CMD ["/etc/init.d/squid","start"]
#CMD ["start"]
#CMD ["start", "batman", "superman"]
#CMD ["/bin/bash", "/sbin/entrypoint.sh"]
#example ENTRYPOINT service nginx start && service ssh start && /bin/bash "use && to separate your code"
#ENTRYPOINT ["/sbin/entrypoint.sh"]

Alpine

Example alpine with apache2:

Dockerfile
FROM alpine:3.11
 
LABEL version="1.4"
LABEL maintainer="Thomas Roehm"
 
#ENV http_proxy "http://proxy:80"
#ENV https_proxy "https://proxy:80"
#ENV no_proxy="localhost,127.0.0.1,.local"
 
#ARG VERSION
 
RUN set -ex;
 
RUN apk update && apk upgrade && \
    apk add --no-cache \
    bash \
    tini \
    tar \
    xz \
    wget \
    less \
    man man-pages \
    mdocml-apropos \
    busybox-extras \
    curl \
    make \
    gcc \
    g++ \
    apache2 \
    apache2-ssl \
    apache2-ldap \
    apache2-utils
 
RUN makewhatis
 
RUN rm -rf /var/cache/apk/* && \
    #mkdir /var/www/htdocs && \
    #chown -R apache:www-data /var/www/htdocs && \
    mkdir /etc/apache2/certificate && \
    echo 'alias ll="ls -alh"' >> ~/.bashrc && \
    echo 'alias ..="cd .."' >> ~/.bashrc && \
    echo 'alias ...="cd ../.."' >> ~/.bashrc
 
COPY certificate/* /etc/apache2/certificate/
COPY httpd.conf /etc/apache2/
COPY ssl.conf /etc/apache2/conf.d/
COPY index.html /var/www/localhost/htdocs/
 
WORKDIR /etc/apache2
 
#USER apache
 
#EXPOSE 80 443
#ENTRYPOINT ["/bin/sh", "-c", "/bin/bash"]                                  #exec form
#ENTRYPOINT /bin/bash                                                       #shell form
#ENTRYPOINT ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]                    #exec form
#ENTRYPOINT /usr/sbin/httpd -D FOREGROUND -f /etc/apache2/httpd.conf        #shell form
#ENTRYPOINT /sbin/tini /usr/sbin/httpd -D FOREGROUND -f /etc/apache2/httpd.conf
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["/usr/sbin/httpd", "-D", "FOREGROUND", "-f", "/etc/apache2/httpd.conf"]

Build:

docker build --no-cache -t alpine-apache2:3.11 .
docker run -it -d -p 80:8080 -p 443:8443 --hostname myhost.local --name=alpine-apache2-1 alpine-apache2:3.11
docker run -it -d -p 80:80 -p 443:443 --hostname myhost.local --name=alpine-apache2-1 alpine-apache2:3.11
docker container ls -a | grep alpine
docker exec -ti PROCESS-ID /bin/bash

Config

Docker Root Dir

Just put this json into /etc/docker/daemon.json:

{
"graph": "/var/lib/docker"
}

Proxy

Files (SLES12 and Ubuntu 16.04/ 18.04):

/etc/systemd/system/docker.service.d/http-proxy.conf
/etc/systemd/system/docker.service.d/https-proxy.conf

Conf:

[Service]
Environment="HTTP_PROXY=proxy:80"
Environment="NO_PROXY=localhost,127.0.0.1"
[Service]
Environment="HTTPS_PROXY=proxy:80"
Environment="NO_PROXY=localhost,127.0.0.1"

Proxy-Setup for container-proxy-communication (version >= 17.07):

~/.docker/config.json
{
 "proxies":
 {
   "default":
   {
     "httpProxy": "http://proxy:8080",
     "httpsProxy": "https://proxy:8443",
     "noProxy": "localhost, 127.0.0.1"
   }
 }
}

Check also on:

https://docs.docker.com/network/proxy/#configure-the-docker-client

docker-compose

Install

Check releases:

https://github.com/docker/compose/releases/

curl -L https://github.com/docker/compose/releases/download/1.18.0/docker-compose-`uname -s`-`uname -m` -o /usr/bin/docker-compose
curl -L https://github.com/docker/compose/releases/download/1.23.2/docker-compose-`uname -s`-`uname -m` -o /usr/bin/docker-compose
chmod +x /usr/bin/docker-compose

or

apt-get install docker-compose

Commands

  
docker-compose up                                                           #inside directory where docker-compose.yml is located!
docker-compose -f docker-compose.yml -f docker-compose.dev.yml up
docker-compose -f /scripts/dockerfiles/gitlab/docker-compose.yml down
docker-compose -f /scripts/dockerfiles/gitlab/docker-compose.yml up -d
docker-compose up -d                                                        #to run your services in the background
docker-compose down
docker-compose ps

Example

docker-compose.yaml (located inside “dockerfile” folder):

version: '2'

services:
  mysql:
    image: mysql:dockerfile
    container_name: test-mysql
    ports:
    #localport:containerport
      - 3306:3306
    environment:
      MYSQL_ROOT_PASSWORD: "mypassword"
    volumes:
      - /data/db:/var/lib/mysql

gitlab-ce:

https://www.ivankrizsan.se/2018/06/23/gitlab-ce-on-docker/

# GitLab CE deployment using two external volumes; one for data and another
# for configuration. These volumes needs to be created prior to starting GitLab
# using the following commands:
# docker volume create gitlab-data
# docker volume create gitlab-config
#
# In addition you may want to change the hostname value in the Docker-Compose
# configuration below to match the name of your server/computer on which
# GitLab is to be run.
#
# Once started, access GitLab using the URL http://localhost:8880.
#
# The following ports are exposed by GitLab:
# 8880 (HTTP)
# 443 (if you configure HTTPS)
# 8080 (used by Unicorn)
# 8822 (used by the SSH daemon)
#
# The GitLab documentation suggests the following line to be added to the
# GITLAB_OMNIBUS_CONFIG environment variable.
# external_url 'http://hostname:8880'
# However, with this line present I am unable to access the GitLab webpage.
version: '2'
#version: '3'

services:
  gitlab:
    image: gitlab/gitlab-ce:latest
    hostname: hostname
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        gitlab_rails['gitlab_shell_ssh_port'] = 8822
    ports:
      - "8443:443"
      - "8880:80"
      - "8822:22"
# The logs directory can be mapped to the logs directory in the same director
# as the docker-compose file using the following entry under volumes:
    volumes:
      - gitlab-config:/etc/gitlab
      - gitlab-data:/var/opt/gitlab
      - ./logs:/var/log/gitlab
    restart: always

volumes:
  gitlab-data:
    external: true
  gitlab-config:
    external: true

Service Unit

“docker-compose” service unit:

# /etc/systemd/system/docker-compose-app.service

[Unit]
Description=Docker Compose Application Service
Requires=docker.service
After=docker.service

[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/srv/docker
ExecStart=/usr/local/bin/docker-compose up -d
ExecStop=/usr/local/bin/docker-compose down
TimeoutStartSec=0

[Install]
WantedBy=multi-user.target

Some container auto start:

[Unit]
#Description=Some service/ container
Description=ubuntu01
Requires=docker.service
After=docker.service

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

[Install]
WantedBy=multi-user.target
docker/docker.1592674921.txt.gz · Last modified: 2020/06/20 19:42 by tmade
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 4.0 International
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki