Docker Tips - stereoboy/Study GitHub Wiki

Docker Compose

Defining your multi-container application with docker-compose.yml

Find my container's network ip

docker inspect <container_name> -f "{{json .NetworkSettings.Networks }}"

Docker Build with Dockerfile

DEBIAN_FRONTEND

Reference

sudo apt-get install debconf-doc
man 7 debconf

Practice

# to set automatic answer for interactive install
RUN echo "yes" | DEBIAN_FRONTEND="teletype" apt-get install -y /<debian_package>.deb 

Docker Image Pruning

docker system prune -a
docker system prune -f
docker system prune
docker image prune -f

Open Another shell

 docker exec -it <container> bash

Use non-root id

  • get <user_name>, <uid> from id -u, <gid> from id -g in HOST
  • access as root: docker exec -it <container> /bin/bash
apt-get install sudo 
groupadd -g <gid> <user_name> // create group
useradd -m -r -u <uid> -g <user_name> <user_name> // create user, -m for creating home directory /home/<user_name>
passwd <user_name>                  
usermod -aG sudo,adm <user_name>  // set user into groups

User is not in the sudoers file. This incident will be reported On using the sudo command if we see the error User is not in the sudoers file. This incident will be reported This means that the user as whom we have logged in and are trying to run the command "sudo" does not have the permission to do so. Only the users listed in /etc/sudoers have the permission to use the command "sudo". To give the sudo permission to a user we need to add the user to the file /etc/sudoers file. Open the file /etc/sudoers as root.

sudo vi /etc/sudoers 
  • Add the line
username ALL = (ALL) ALL 
  • access as user_name: docker exec -it --user $(id -u):$(id -g) <container_name> /bin/bash

Use GUI

X11 Rendering

XSOCK=/tmp/.X11-unix
XAUTH=/tmp/.docker.xauth
touch $XAUTH
xauth nlist $DISPLAY | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge -

docker run  -it \
        --volume=$XSOCK:$XSOCK:rw \
        --volume=$XAUTH:$XAUTH:rw \
        --env="XAUTHORITY=${XAUTH}" \
        --env="DISPLAY"=${DISPLAY} \
    nvidia/cudagl:10.1-devel-ubuntu18.04 \
    /bin/bash

3D Rendering with NVIDIA Drivers

XSOCK=/tmp/.X11-unix
XAUTH=/tmp/.docker.xauth
touch $XAUTH
xauth nlist $DISPLAY | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge -

docker run  --gpus=all -it \
        --volume=$XSOCK:$XSOCK:rw \
        --volume=$XAUTH:$XAUTH:rw \
        --env="XAUTHORITY=${XAUTH}" \
        --env="DISPLAY=${DISPLAY}" \
        --env="NVIDIA_DRIVER_CAPABILITIES=all" \
   nvidia/cudagl:10.1-devel-ubuntu18.04  \
    /bin/bash

Use Docker Hub for sharing

⚠️ **GitHub.com Fallback** ⚠️