|
|
| (32 intermediate revisions by the same user not shown) |
| Line 1: |
Line 1: |
| − | https://www.docker.com/
| |
| | | | |
| − | Docker hub: https://hub.docker.com/
| |
| − |
| |
| − |
| |
| − | Last time I installed it I follwed ChatGPT and everything was perfect!
| |
| − |
| |
| − |
| |
| − | <br />
| |
| − | ==Why use Docker==
| |
| − | * Capture all dependencies as code:
| |
| − | :* Python requerements
| |
| − | :* OS dependencies.
| |
| − |
| |
| − | * Consistent dev and prod environment: You can use the same image for development and production. So you eliminate all the issues that can arrive when changing to another environment in production.
| |
| − |
| |
| − | * Easier collaboration: When you share your code with other developers you can be sure it will work. You eliminate all dependencies issues in another developer's machines.
| |
| − | :* Different version of Python / Different version of databases / Different version of SDK.
| |
| − |
| |
| − |
| |
| − | <br />
| |
| − | ==Docker basics==
| |
| − | We have already learned how to download Docker images using the «docker pull» command and how to create a container using the «docker run» command. We will now learn about other basic Docker commands. We can use the «docker ps» command to see all the containers in our machine:
| |
| − |
| |
| − | sudo docker ps -a
| |
| − |
| |
| − | We should be able to see the Postgres container running.
| |
| − |
| |
| − | [[File:Output_of_the_dockerpa-a_command.png|1000px|thumb|center|Output of the docker pa -a command]]
| |
| − |
| |
| − | Each container and image has an associated ID that looks like the following:
| |
| − | c6f7dfc1a4c8
| |
| − |
| |
| − | We can use the following command to stop a running Docker container:
| |
| − | sudo docker stop INSERT_CONTAINER_ID_HERE
| |
| − | sudo docker stop c6f7dfc1a4c8
| |
| − |
| |
| − | Similarly, we can run a Docker container using the start command:
| |
| − | sudo docker start c6f7dfc1a4c8
| |
| − |
| |
| − | Please note that the run command is used to create a new Docker container while the start command is used to run an existingDocker container given its ID.
| |
| − |
| |
| − | We can use the following command to remove a Docker container:
| |
| − | sudo docker rm c6f7dfc1a4c8
| |
| − |
| |
| − | Please note that before you can remove a Docker container, you must stop it. The following command can be used to remove aDocker image:
| |
| − | sudo docker rmi INSERT_IMAGE_ID_HERE
| |
| − |
| |
| − | Please note that before you can remove a Docker image, you must stop and remove all its associated containers.
| |
| − |
| |
| − |
| |
| − | <br />
| |