# < -------------------------- Docker installation -------------------------- >
# To start docker
sudo systemctl start docker
# To run hello-world
sudo docker run hello-world
# To manage Docker as a non-root user
# Create the docker group.
sudo docker run hello-world
# Add your user to the docker group.
sudo usermod -aG docker $USER
# Log out and log back in so that your group membership is re-evaluated
# You can also run the following command to activate the changes to groups:
newgrp docker
# Verify that you can run docker commands without sudo
docker run hello-world
# Configure Docker to start on boot with systemd
sudo systemctl enable docker.service
sudo systemctl enable containerd.service
# To stop this behavior, use disable instead.
sudo systemctl disable docker.service
sudo systemctl disable containerd.service
# Configure default logging driver
# The default logging driver, json-file, writes log data to JSON-formatted files on
the host filesystem. Over time, these log files expand in size, leading to
potential exhaustion of disk resources.
# To avoid issues with overusing disk for log data, consider one of the following
options:
# Configure the json-file logging driver to turn on log rotation.
# To use the json-file driver as the default logging driver, set the log-driver and
log-opts keys to appropriate values in the daemon.json file, which is located in
/etc/docker/ on Linux hosts or C:\ProgramData\docker\config\ on Windows Server. If
the file does not exist, create it first.
# The following example sets the log driver to json-file and sets the max-size and
max-file options to enable automatic log-rotation.
{
"log-driver": "json-file",
"log-opts": {
"max-size": "10m",
"max-file": "3"
}
}
# Restart Docker for the changes to take effect for newly created containers.
Existing containers don't use the new logging configuration automatically.
# < -------------------------- Docker management -------------------------- >
# Mostrar una lista de todos los contenedores en el sistema
docker ps -a
docker container ls -a
# Muestra una lista de todas las imágenes de Docker almacenadas localmente en la
máquina
docker image ls
docker images
# Ejecutar la imagen
docker run hello-world
# Borrar contenedor
docker rm hello-world
# Crear contenedor con el nombre que quiera (hello-1)
docker run -c --name=hello-1 hello-world
# Tengo que borrar los contenedores para poder borrar la imagen