example to create docker image in tar file
tar \
--numeric-owner \
--exclude=/boot \
--exclude=/dev \
--exclude=/pack \
--exclude=/proc \
--exclude=/sys \
--exclude=/mnt \
--exclude=/var/cache \
--exclude=/usr/share/{foomatic,backgrounds,perl5,fonts,cups,qt4,groff,kde4,icons,pixmaps,emacs,gnome-background-properties,sounds,gnome,games,desktop-directories} \
--exclude=/var/log \
-zcvf \
/pack/slax.tar.gz /
after load the image to docker
cat slax.tar.gz | docker import - slax
save the image as a tarball
docker save repositoryname:tag > repotag.tar
zip the image
gzip repotag.tar
copy the tarball to the new machine
scp repotag.tar.gz <foreign machine>
unzip The tarball
gunzip repotag.tar.gz
load the docker image
docker load < repotar.tar
find the Image ID
docker images
tag the image
docker tag repositoryname:tag
docker run -i -t --rm ubuntu /bin/bash
- -t flag assigns a pseudo-tty or terminal inside the new container.
- -i flag allows you to make an interactive connection by grabbing the standard input (STDIN) of the container.
- --rm flag automatically removes the container when the process exits. By default, containers are not deleted. This container exists until we keep the shell session and terminates when we exit the session (like an SSH session with a remote server).
docker run --name daemon -d ubuntu /bin/sh -c "while true; do echo hello world; sleep 1; done"
- --name daemon assigns daemon name to a new container. If you don’t specify a name explicitly, Docker will generate and assign it automatically.
- -d flag runs the container in the background (i.e., daemonizes it).
docker ps -a
- docker ps is a command to list containers.
- -a shows all containers (without -a flag ps will show only running containers).
check the logs and see what the daemon container is doing right now
docker logs -f daemon
let’s stop the daemon container
docker stop daemon
delete all containers
docker rm $(docker ps -a -q)
delete all images
docker rmi $(docker images -q)
to commit changes to existing Docker images
docker commit 782ce39021a0 wordpress:new2