how to install and configure docker-ce on Ubuntu 18.04

  • install the new docker version, docker-ce
sudo apt update
sudo apt install docker.io
docker version

  • useful docker commands
CID=$(docker run -p hostPort:dockerPort image-name)
docker ps
docker ps -a
docker logs $CID
docker port $CID
docker stop $CID
docker start $CID
docker rm $CID
docker images
docker pull image-name
docker commit $CID new-image-name

export/import vs save/load
https://tuhrig.de/difference-between-save-and-export-in-docker/


  • how to create a base image
sudo debootstrap bionic bionic-rootfs
sudo tar -C bionic-rootfs -c . | docker import - mslee/bionic
docker run -it mslee/bionic bash
    apt install software-properties-common
    add-apt-repository 'deb http://kr.archive.ubuntu.com/ubuntu/ bionic-updates main restricted'
    add-apt-repository 'deb http://kr.archive.ubuntu.com/ubuntu/ bionic universe'
    add-apt-repository 'deb http://kr.archive.ubuntu.com/ubuntu/ bionic-updates universe'
    add-apt-repository 'deb http://kr.archive.ubuntu.com/ubuntu/ bionic multiverse'
    add-apt-repository 'deb http://kr.archive.ubuntu.com/ubuntu/ bionic-updates multiverse'
    add-apt-repository 'deb http://security.ubuntu.com/ubuntu bionic-security main restricted'
    add-apt-repository 'deb http://security.ubuntu.com/ubuntu bionic-security universe'
    add-apt-repository 'deb http://security.ubuntu.com/ubuntu bionic-security multiverse'

https://docs.docker.com/develop/develop-images/baseimages/
https://www.mirantis.com/blog/how-do-i-create-a-new-docker-image-for-my-application/


  • how to provide multiple services in a docker container using systemd
# in the host (i.e. setup script should be added first into docker container)
vi setup
chmod 755 setup
docker run -it mslee/bionic bash
docker exec <cid> mkdir /host
docker cp setup <cid>:/sbin/
docker commit <cid> mslee/bionic-systemd
docker stop <cid>
docker run --rm --privileged -v /:/host mslee/bionic-systemd setup
docker stop <cid>
docker run -d --name mysystemd --security-opt seccomp=unconfined --tmpfs /run --tmpfs /run/lock -v /sys/fs/cgroup:/sys/fs/cgroup:ro -t mslee/bionic-systemd
cat /sbin/setup
#!/bin/sh
set -eu

if nsenter --mount=/host/proc/1/ns/mnt -- mount | grep /sys/fs/cgroup/systemd >/dev/null 2>&1; then
  echo 'The systemd cgroup hierarchy is already mounted at /sys/fs/cgroup/systemd.'
else
  if [ -d /host/sys/fs/cgroup/systemd ]; then
    echo 'The mount point for the systemd cgroup hierarchy already exists at /sys/fs/cgroup/systemd.'
  else
    echo 'Creating the mount point for the systemd cgroup hierarchy at /sys/fs/cgroup/systemd.'
    mkdir -p /host/sys/fs/cgroup/systemd
  fi

  echo 'Mounting the systemd cgroup hierarchy.'
  nsenter --mount=/host/proc/1/ns/mnt -- mount -t cgroup cgroup -o none,name=systemd /sys/fs/cgroup/systemd
fi
echo 'Your Docker host is now configured for running systemd containers!'

Running systemd within a Docker Container
https://developers.redhat.com/blog/2014/05/05/running-systemd-within-docker-container/
https://developers.redhat.com/blog/2016/09/13/running-systemd-in-a-non-privileged-container/
https://lwn.net/Articles/676831/
https://developers.redhat.com/blog/2019/04/24/how-to-run-systemd-in-a-container/
https://hub.docker.com/r/solita/ubuntu-systemd
https://www.linode.com/docs/quick-answers/linux/start-service-at-boot/


  • docker desktop
git clone https://github.com/kstenerud/docker-desktops.git
cd docker-desktops/
cp configuration.example configuration
vi configuration
cd base-desktop/
vi Dockerfile
./build.sh
cd ../desktop
./build.sh
./run.sh

https://hub.docker.com/r/queeno/ubuntu-desktop
https://hub.docker.com/r/dorowu/ubuntu-desktop-lxde-vnc
https://github.com/kstenerud/docker-desktops


  • creating your own docker desktop
apt install software-properties-common
add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) main universe restricted multiverse"
add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc)-updates main universe restricted multiverse"
add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc)-restricted main universe restricted multiverse"
add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc)-security main universe restricted multiverse"
add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc)-backports main universe restricted multiverse"
apt update
apt install -y x2goserver x2goserver-xsession lxde openssh-server

https://docs.docker.com/develop/develop-images/dockerfile_best-practices/


  • image push/pull to your own repository in dockerhub
# your docker hub repository: https://cloud.docker.com/repository/list
docker login
docker tag desktop:latest sang0627/rdtest1:v1
docker push sang0627/rdtest1:v1

#image pull from dockerhub repository
docker pull sang0627/rdtest1:v1

your repositories
https://cloud.docker.com/repository/list


  • tips for command
# clear DNS cache
sudo systemd-resolve --flush-caches
sudo /etc/init.d/dns-clean start

# stop all docker containers
docker container stop $(docker container ls| awk '{print $1}')

# how to get docker container IP
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $cid

# how to get docker container process ID
docker inspect -f ’{{.State.Pid}}’ $cid

  • helpful documents

Manage data in Docker
https://docs.docker.com/storage/

About storage drivers
https://docs.docker.com/storage/storagedriver/

Docker storage drivers
https://docs.docker.com/storage/storagedriver/select-storage-driver/

Leave a Reply

Your email address will not be published. Required fields are marked *