Docker is a computer program that performs operating-system-level virtualization, also known as "containerization". It was first released in 2013 and is developed by Docker, Inc. Docker is used to run software packages called "containers".


Get Docker from the Docker Community website.

Get also Docker Compose.

Setup, e.g. on Ubuntu.

# Install on Ubuntu as a service.
sudo mkdir /etc/docker
sudo cat << EOF > /etc/docker/daemon.json
  "exec-opts": ["native.cgroupdriver=cgroupfs"]
cat << EOF_D >
sudo apt -y remove docker docker-engine
sudo apt update
sudo apt -y install \
    linux-image-extra-$(uname -r) \
sudo apt -y install \
    apt-transport-https \
    ca-certificates \
    curl \
curl -fsSL | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository \
   "deb [arch=amd64] \
   $(lsb_release -cs) \
sudo apt update
sudo apt -y install docker-ce
systemctl daemon-reload
systemctl restart docker
sudo chmod +x && ./
sudo systemctl status docker
sudo journalctl -fu docker
sudo journalctl -lxeu docker

Configure with environment variables.

  • DOCKER_BACKGROUND_PROCESS = Run as background process (default is true)
  • DOCKER_SPARK_MASTER = MASTER for Spark (default is local[*]).
  • DOCKER_NOTEBOOK_DIR = Folder where the notes reside (default is /notebook).
  • DOCKER_WEB_PORT = The HTTP port (default is 8666).
  • DOCKER_HADOOP_CONF_DIR = The folder for the Hadoop configuration file on the host (default is /etc/hadoop/conf).

Hello World

docker run --name nginx --rm -d -it -p 8098:80 nginx:stable-alpine
echo http://localhost:8098
docker ps
docker exec -it nginx /bin/sh
docker attach nginx # Detach with CTRL+P+Q
docker inspect nginx
docker stop nginx
docker run --name echoserver --rm -d -it -p 8081:80
echo http://localhost:8081
docker exec -it echoserver /bin/sh
docker attach echoserver # Detach with CTRL+P+Q
docker stop echoserver
docker run --name simple-service --rm -d -it -p 9876:9876 datalayer/simple-service:0.0.1
echo http://localhost:9876/info
echo http://localhost:9876/env
docker exec -it simple-service ps -ef
docker exec -it simple-service /bin/bash
docker attach simple-service # Detach with CTRL+P+Q
docker stop simple-service
docker rm simple-service
docker run --name centos --rm centos:centos7 /bin/echo 'Hello world'
docker run --name centos --rm -it --rm centos:centos7 /bin/bash
docker run --name centos --rm centos:centos7 yum update
docker run --name centos --rm -it --dns= centos:centos7 /bin/bash
docker run --name centos --rm --mac-address=a8:20:66:40:97:3d --net=bridge --bip= centos:centos7 yum update


# Get Host IP on MacOs -
docker run -it --rm busybox ping docker.for.mac.localhost
docker inspect --format '{{ .NetworkSettings.IPAddress }}' container_name_or_id


docker volume ls
docker volume inspect <foo>
docker volume prune # !!! removes all currently not used volumes...


Docker Compose Docs.

About name resolution.


Orchestration - Run Swarm and Kubernetes Interchangeably


Docker Swarm Overview.

Docker Swarm Service.

Docker Swarm Stack Deploy.

docker swarm init.
docker service create --name registry --publish published=5000,target=5000 registry:2
docker service ls
curl http://localhost:5000/v2/
mkdir stackdemo
cd stackdemo
cat <<EOF >
from flask import Flask
from redis import Redis

app = Flask(__name__)
redis = Redis(host='redis', port=6379)
def hello():
    count = redis.incr('hits')
    return 'Hello World! I have been seen {} times.\n'.format(count)

if __name__ == "__main__":"", port=8000, debug=True)
cat <<EOF > requirements.txt
cat <<EOF > Dockerfile
FROM python:3.4-alpine
ADD . /code
RUN pip install -r requirements.txt
CMD ["python", ""]
cat <<EOF > docker-compose.yml
version: '3'
    build: .
      - "8000:8000"
    image: redis:alpine
docker-compose up -d
docker-compose ps
for i in {0..20}; do curl http://localhost:8000; sleep 1s; done
docker-compose down --volumes
docker-compose push
docker swarm init
docker stack deploy --compose-file docker-compose.yml stackdemo
docker stack services stackdemo
for i in {0..20}; do curl http://localhost:8000; sleep 1s; done
curl http://address-of-other-node:8000
docker stack rm stackdemo
docker service rm registry
docker swarm leave --force

Docker Swarm Visualizer

Local Registry

# docker run -p 5000:5000 registry
docker run -d -p 5000:5000 --restart=always --name registry registry:2
curl -X GET http://localhost:5000/v2/_catalog
# Put in your local registry an imaage, e.g. simple-service:0.0.1
docker pull localhost:5000/datalayer/simple-service:0.0.1
docker container stop registry && docker container rm -v registry

Squash Image

docker save datalayer/simple-service:0.0.1 -o simple-service-image.tar
docker history datalayer/simple-service:0.0.1
docker inspect datalayer/simple-service:0.0.1 | grep -A 6 Layers

Prune Containers and Images

# Delete all containers.
# docker rm -f $(docker ps -a -q)
dla docker-prune

results matching ""

    No results matching ""