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 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

  • 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 bionic-updates main restricted'
    add-apt-repository 'deb bionic universe'
    add-apt-repository 'deb bionic-updates universe'
    add-apt-repository 'deb bionic multiverse'
    add-apt-repository 'deb bionic-updates multiverse'
    add-apt-repository 'deb bionic-security main restricted'
    add-apt-repository 'deb bionic-security universe'
    add-apt-repository 'deb bionic-security multiverse'

  • 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
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.'
  if [ -d /host/sys/fs/cgroup/systemd ]; then
    echo 'The mount point for the systemd cgroup hierarchy already exists at /sys/fs/cgroup/systemd.'
    echo 'Creating the mount point for the systemd cgroup hierarchy at /sys/fs/cgroup/systemd.'
    mkdir -p /host/sys/fs/cgroup/systemd

  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
echo 'Your Docker host is now configured for running systemd containers!'

Running systemd within a Docker Container

  • docker desktop
git clone
cd docker-desktops/
cp configuration.example configuration
vi configuration
cd base-desktop/
vi Dockerfile
cd ../desktop

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

  • image push/pull to your own repository in dockerhub
# your docker hub repository:
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

  • 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

About storage drivers

Docker storage drivers

Leave a Reply

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