journalctl -eu docker
Some Docker commands
Create an image linux centos from docker repository : docker run -it centos
and run into a container
docker run -i -t centos
OR
create your custom centos image like this:
- create a folder mkdir centos1, and go inside cd centos1
- download the image from here into the folder centos1
- create the file Dockerfile into the folder centos1
FROM scratch
ADD CentOS-7-20140625-x86_64-docker_01.img.tar.xz /
LABEL name=”CentOS Base Image” \
vendor=”CentOS” \
license=”GPLv2″ \
build-date=”20190426″
CMD [“/bin/bash”]
4. run this command into the folder centos1 : docker build -t name_of_image .
5. run the command for view list of your images : docker images
6. run this command to enter into the image : docker run -it name_of_image
- To save an image to any file path or shared NFS place see the following example.Get the image id by doing:
sudo docker images
Say you have an image with id “matrix-data”.
Save the image with id:
sudo docker save -o /home/matrix/matrix-data.tar matrix-data
Copy the image from the path to any host. Now import to your local Docker installation using:
sudo docker load -i <path to copied image file>
Remove images
docker image ls
The output should look something like this:
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 75835a67d134 7 days ago 200MB
ubuntu latest 2a4cca5ac898 2 months ago 111MB
linuxize/fedora latest a45d6dca3361 3 months ago 311MB
java 8-jre e44d62cf8862 3 months ago 311MB
Once you’ve located the images you want to remove, pass their IMAGE ID
to the docker image rm
command. For example to remove the first two images listed in the output above run:
docker image rm 75835a67d134 2a4cca5ac898
If you get an error similar to the following, it means that the image is used by an existing container. To remove the image you will have to remove the container first.
Remove one or more containers
To remove one or more Docker images use the docker container rm
command followed by the ID of the containers you want to remove.
You can get a list of all active and inactive containers by passing the -a
flag to the docker container ls
command:
docker container ls -a
The output should look something like this:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cc3f2ff51cab centos "/bin/bash" 2 months ago Created competent_nightingale
cd20b396a061 solita/ubuntu-systemd "/bin/bash -c 'exec …" 2 months ago Exited (137) 2 months ago systemd
fb62432cf3c1 ubuntu "/bin/bash" 3 months ago Exited (130) 3 months ago jolly_mirzakhani
Once you know the CONTAINER ID
of the containers you want to delete, pass it to the docker container rm
command. For example to remove the first two containers listed in the output above run:
docker container rm cc3f2ff51cab cd20b396a061
If you get an error similar to the following, it means that the container is running. You’ll need to stop the container before removing it.