###### Docker ###### Install a new image =================== .. code-block:: bash docker search docker pull Run image ========= * Runs a new container of image in interactive mode and starts a bash .. code-block:: bash docker run -i -t bash * Start an existing container .. code-block:: bash docker start -i List installed images ===================== .. code-block:: bash docker images List running containers ======================= .. code-block:: bash docker ps Save changes ============ .. code-block:: bash docker commit Export images ============= .. code-block:: bash docker save > docker load -i Update images ============= * Only one .. code-block:: bash docker pull * All images .. code-block:: bash docker images | awk '{print $1}' | xargs -L1 docker pull Port forward ============ * Starts in daemon mode and forwards container port 80 to host port 8888 but only on loopback interface .. code-block:: bash docker run -d -p 127.0.0.1:8888:80 * Automatically forward all ports .. code-block:: bash docker run -P Set fixed IP for container ========================== .. code-block:: bash docker run --ip= --default-gateway= Get IP of container =================== .. code-block:: bash docker inspect | grep IPAddress Share directory between host and container ========================================== * Via Dockerfile .. code-block:: bash VOLUME ["/var/volume1", "/var/volume2"] * Via command-line .. code-block:: bash -v /path/on/host:/path/in/container Allow docker container to access DISPLAY ======================================== .. code-block:: bash xhost +local:docker Display CPU / RAM usage of container ==================================== .. code-block:: bash docker stats Get STDOUT / STDERR from container =================================== .. code-block:: bash docker log Get a shell on a running container ================================== .. code-block:: bash docker exec -it bash Example docker file =================== .. code-block:: bash # # base image is latest official redhat rhel7 # from rhel7:latest # Update the system RUN yum update -y # Install web server RUN yum install -y httpd # Copy files to image #COPY ./public-html/ /usr/local/apache2/htdocs/ #COPY ./my-httpd.conf /usr/local/apache2/conf/httpd.conf # Start the service EXPOSE 80 CMD ["-D", "FOREGROUND"] ENTRYPOINT ["/usr/sbin/httpd"] Image from scratch ================== .. code-block:: bash debootstrap bullseye bullseye tar -C bullseye -c . | docker import - mydebian * Or via Dockerfile .. code-block:: bash FROM scratch COPY some_static_binary / ENTRYPOINT ["/some_static_binary"] Troubleshooting =============== * ``Couldn’t create Tag store: unexpected end of JSON input`` .. code-block:: bash rm /var/lib/docker/repositories