informatica:sistemas_operativos:cursos:docker_avanzado:ejercicios_practicos
Diferencias
Muestra las diferencias entre dos versiones de la página.
| Próxima revisión | Revisión previa | ||
| informatica:sistemas_operativos:cursos:docker_avanzado:ejercicios_practicos [2023/10/10 18:49] – creado tempwin | informatica:sistemas_operativos:cursos:docker_avanzado:ejercicios_practicos [2023/10/10 18:58] (actual) – tempwin | ||
|---|---|---|---|
| Línea 1: | Línea 1: | ||
| ====== Ejercicios prácticos (Docker avanzado) ====== | ====== Ejercicios prácticos (Docker avanzado) ====== | ||
| + | Contenido perteneciente al curso [[informatica: | ||
| + | 1. Check that docker is correctly running and that you have permission to use the engine | ||
| - | 1. Check that docker is correctly running and that you have permission to use the | + | < |
| - | engine | + | |
| docker info | docker info | ||
| - | 2. (pull) Pull an image from the official registry, eg: debian: | + | </ |
| - | browse https:// | + | |
| + | 2. (**pull**) Pull an image from the official registry, eg: debian: | ||
| + | |||
| + | < | ||
| docker pull debian: | docker pull debian: | ||
| - | debian is the repository name, and :latest is a tag that identifies an image in | + | </ |
| - | the repository (for the case of the debian repository it is the latest stable release). | + | |
| - | You could also write :jessie or :stretch to use a specific version of the | + | debian is the repository name, and '' |
| - | distribution. | + | |
| + | You could also write '' | ||
| You can check that your image is present in the docker engine: | You can check that your image is present in the docker engine: | ||
| + | |||
| + | < | ||
| docker images | docker images | ||
| - | 3. (run) Run a container from this image. | + | </ |
| + | |||
| + | 3. (**run**) Run a container from this image. | ||
| + | |||
| + | < | ||
| docker run debian: | docker run debian: | ||
| - | (you may also write docker run debian which is equivalent: :latest is the | + | </ |
| - | defaut tag if none are provided) | + | |
| - | Nothing happens? actually the container has already terminated, you can display | + | (you may also write docker run debian which is equivalent: |
| - | it with docker ps , but add -a/--all because non-running container are not | + | |
| - | displayed by default. | + | Nothing happens? actually the container has already terminated, you can display it with '' |
| + | |||
| + | < | ||
| docker ps -a | docker ps -a | ||
| - | The default command of the debian image is /bin/bash and by default docker | + | </ |
| - | containers are run without stdin (it is redirected from /dev/null ). Thus bash | + | |
| - | exits immediately. | + | The default command of the debian image is '' |
| - | 4. (run a command) You may override the default command by providing extra | + | |
| - | arguments after the image name. Then this command will be executed (instead | + | 4. (**run a command**) You may override the default command by providing extra arguments after the image name. Then this command will be executed (instead of bash). |
| - | of bash). | + | |
| + | < | ||
| docker run debian ls /bin | docker run debian ls /bin | ||
| docker run debian cat /etc/motd | docker run debian cat /etc/motd | ||
| - | 5. (stdin) Let's go back to bash, this time we want interact with the shell. To keep | + | </ |
| - | stdin open, we launch the container with -i/ | + | |
| + | 5. (**stdin**) Let's go back to bash, this time we want interact with the shell. To keep stdin open, we launch the container with '' | ||
| + | |||
| + | < | ||
| docker run -i debian | docker run -i debian | ||
| - | The container runs, but displays nothing. Actually bash is running in batch | + | </ |
| - | mode. You can try to execute commands (eg: ls , id , hostname ...) and you will | + | |
| - | see the result. | + | The container runs, but displays nothing. Actually bash is running in batch mode. You can try to execute commands (eg: '' |
| - | Bash is in batch mode because it is not running on a terminal (its stdout is a | + | |
| - | pipe, not a tty). | + | Bash is in batch mode because it is not running on a terminal (its stdout is a pipe, not a tty). |
| - | 6. (tty) To have a real interactive shell inside our container, we need to allocate a | + | |
| - | tty with -t/--tty | + | 6. (**tty**) To have a real interactive shell inside our container, we need to allocate a tty with '' |
| + | |||
| + | < | ||
| docker run -t -i debian | docker run -t -i debian | ||
| - | 7. (start) You can exit your container and display the list of all containers: | + | </ |
| + | |||
| + | 7. (**start**) You can exit your container and display the list of all containers: | ||
| + | |||
| + | < | ||
| docker ps -a | docker ps -a | ||
| - | It is possible to start them again with docker start . Like the run command, | + | </ |
| - | you may use -i to have stdin open. Note that start expects you to tell which | + | |
| - | container you want to start. Containers may be identified either by their id (first | + | It is possible to start them again with '' |
| - | column of docker ps ) or by their name (last column). You may provide only | + | |
| - | the first digits of the id (as long as there is no ambiguity). Examples: | + | < |
| docker start -i 85bcdca6c38f | docker start -i 85bcdca6c38f | ||
| docker start -i 85bcd | docker start -i 85bcd | ||
| docker start -i 85 | docker start -i 85 | ||
| - | docker start -i | + | docker start -i 85bcdca6c38f07e3f8140cbf8b4ad37fd80d731b87c6945012479439a450a443 |
| - | 85bcdca6c38f07e3f8140cbf8b4ad37fd80d731b87c6945012479439a450a443 | + | |
| docker start -i pensive_hodgkin | docker start -i pensive_hodgkin | ||
| - | 8. (commit) You can modify files inside a container. If you restart the same | + | </ |
| - | container you can note that these changes are still present. However they will | + | |
| - | not be present in the other container (even if they are running the same image) | + | 8. (**commit**) You can modify files inside a container. If you restart the same container you can note that these changes are still present. However they will not be present in the other container (even if they are running the same image) because docker uses a copy-on-write filesystem. |
| - | because docker uses a copy-on-write filesystem. Use the command docker | + | |
| - | diff to show the difference of a container from its image. | + | Use the command |
| - | Remember that all changes inside a container are thrown away when the | + | |
| - | container is removed. If we want save a container filesytem for later use, we | + | Remember that all changes inside a container are thrown away when the container is removed. If we want save a container filesytem for later use, we have to commit the conainer (i.e take a snapshot). |
| - | have to commit the conainer (i.e take a snapshot). | + | |
| + | < | ||
| docker commit CONTAINER | docker commit CONTAINER | ||
| - | This operation creates a new image (visible in docker images ). This image in | + | </ |
| - | turn can be used to start a new container. | + | |
| - | Note: docker commit does not affect the state of the container. If it is running, | + | This operation creates a new image (visible in docker images ). This image in turn can be used to start a new container. |
| - | then it just keeps running. You may take as many snapshots as you like. | + | |
| - | 9. (rm) You now have too many dead containers in your engine. You should use | + | Note: '' |
| - | docker rm to remove them. Alternatively you can run docker container | + | |
| - | prune which removes all dead container. | + | 9. (**rm**) You now have too many dead containers in your engine. You should use '' |
| - | 10. (extras) If you still have extra time, you can experiment | + | |
| - | o the other docker run options we introduced so far: | + | 10. (**extras**) If you still have extra time, you can experiment o the other docker run options we introduced so far: |
| - | ▪ --rm to remove the container automatically when it terminates | + | |
| - | ▪ -d/--detach to run a container in the background | + | * '' |
| - | ▪ -u/--user to run the container as a different user | + | * '' |
| - | ▪ -w/ | + | * '' |
| - | ▪ -e/--env to set an environment variable | + | * '' |
| - | ▪ -h/ | + | * '' |
| - | the container) | + | * '' |
| - | ▪ --name to set a different name (the name of the container in the | + | * '' |
| - | docker engine) | + | |
| - | ▪ also you may type docker run --help to display all | + | |
| - | configuration keys | + | Other docker commands (note: some of these commands require the container to be running, just launch docker |
| - | o other docker commands (note: some of these commands require the | + | |
| - | container to be running, just launch docker run -d -t -i debian to | + | * '' |
| - | have one that keeps running in the background) | + | * '' |
| - | ▪ docker inspect to display the metadata of a container (json | + | * '' |
| - | format) | + | * '' |
| - | ▪ docker cp to transfer files from/into the container | + | * '' |
| - | ▪ docker exec to have launch a separate command (very useful | + | * '' |
| - | for providing a debugging shell -> docker exec -t -i | + | * '' |
| - | CONTAINER bash ) | + | |
| - | ▪ docker top to display the processes running inside the container | + | |
| - | ▪ docker stats to display usage statistics | + | |
| - | ▪ docker logs to display the container output | + | |
| - | ▪ docker attach to reattach to the console of a detached container | + | |
informatica/sistemas_operativos/cursos/docker_avanzado/ejercicios_practicos.1696956590.txt.gz · Última modificación: por tempwin
