Docker¶
Install a new image¶
docker search <whatever>
docker pull <image>
Run image¶
Runs a new container of image in interactive mode and starts a bash
docker run -i -t <image> bash
Start an existing container
docker start -i <container_id>
List installed images¶
docker images
List running containers¶
docker ps
Save changes¶
docker commit <container_id> <image_name>
Export images¶
docker save <image> > <archive_file>
docker load -i <archive_file>
Update images¶
Only one
docker pull <image>
All images
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
docker run -d -p 127.0.0.1:8888:80 <image>
Automatically forward all ports
docker run -P <image>
Set fixed IP for container¶
docker run --ip=<container_ip> --default-gateway=<gw_ip>
Get IP of container¶
docker inspect <container_id> | grep IPAddress
Allow docker container to access DISPLAY¶
xhost +local:docker
Display CPU / RAM usage of container¶
docker stats <container_id>
Get STDOUT / STDERR from container¶
docker log <container_id>
Get a shell on a running container¶
docker exec -it <container_id> bash
Example docker file¶
#
# 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¶
debootstrap bullseye bullseye
tar -C bullseye -c . | docker import - mydebian
Or via Dockerfile
FROM scratch
COPY some_static_binary /
ENTRYPOINT ["/some_static_binary"]
Troubleshooting¶
Couldn’t create Tag store: unexpected end of JSON input
rm /var/lib/docker/repositories