howto:specific:learndocker
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| howto:specific:learndocker [2025/01/16 12:41] – Added rest of background from workshop alexdavis | howto:specific:learndocker [2025/01/22 16:51] (current) – [Workshop tasks] alexdavis | ||
|---|---|---|---|
| Line 11: | Line 11: | ||
| - Start with an application | - Start with an application | ||
| - Write a **Dockerfile** that replicates the setup needed for the application | - Write a **Dockerfile** that replicates the setup needed for the application | ||
| - | - Use the **Docker Client** to build your application into an **image** | + | - Use the **Docker Client** to build your application into an **image** using the **Dockerfile** |
| - Then use the **Client** again to run the **image** as a **container** | - Then use the **Client** again to run the **image** as a **container** | ||
| - Manage the running and configuration of multiple containers with **Docker Compose** | - Manage the running and configuration of multiple containers with **Docker Compose** | ||
| Line 18: | Line 18: | ||
| == Dockerfiles == | == Dockerfiles == | ||
| Dockerfiles are text files placed in the root of a project directory with instructions to build a **container**. They are comprised of **layers**, where each layer is modification to the image created by every layer " | Dockerfiles are text files placed in the root of a project directory with instructions to build a **container**. They are comprised of **layers**, where each layer is modification to the image created by every layer " | ||
| - | <code> | + | <file> |
| FROM python: | FROM python: | ||
| Line 34: | Line 34: | ||
| CMD [" | CMD [" | ||
| - | </code> | + | </file> |
| Each line is a layer, and does the following: | Each line is a layer, and does the following: | ||
| - Loads the python 3.10 base image | - Loads the python 3.10 base image | ||
| Line 48: | Line 48: | ||
| Containers are created from images. Containers are similar to virtual machines, but are not the same thing. They run applications in isolated, self-reliant environments. One of the advantages of Docker is that pretty much anywhere it runs, containers will run. | Containers are created from images. Containers are similar to virtual machines, but are not the same thing. They run applications in isolated, self-reliant environments. One of the advantages of Docker is that pretty much anywhere it runs, containers will run. | ||
| == Compose == | == Compose == | ||
| - | TODO | + | Docker Compose is an extra tool for managing the running of multiple-container applications. It makes things like networking easier, as well as configuration by storing parameters manually passed to //docker run// in a configuration file (normally called // |
| + | |||
| + | The // | ||
| + | < | ||
| + | version: " | ||
| + | services: | ||
| + | flask: | ||
| + | image: localhost/ | ||
| + | container_name: | ||
| + | ports: | ||
| + | - YourPort: | ||
| + | environment: | ||
| + | - DISPLAY_NAME=YourName | ||
| + | networks: | ||
| + | - external | ||
| + | |||
| + | # Below fixes a problem with Tardis container networking | ||
| + | networks: | ||
| + | external: | ||
| + | name: podman | ||
| + | external: true | ||
| + | </ | ||
| + | |||
| + | ==== Workshop tasks ==== | ||
| + | Below is the interactive tasks from the workshop for people to work through at their own pace. Familiarity with Linux and Git is expected. [[https:// | ||
| + | === Setup === | ||
| + | Sign up to Tardis if you haven' | ||
| + | Clone the workshop repo: | ||
| + | git clone https:// | ||
| + | Look inside the Dockerfile, what does each layer do? | ||
| + | === Build an image === | ||
| + | Run the below in the same directory as the Dockerfile to build the image. Change " | ||
| + | < | ||
| + | See the list of saved images with: | ||
| + | < | ||
| + | === Run a container === | ||
| + | Start your container with the following command, changing the display name argument and the port number. If the port number is in use run //docker rm flask// then try a different port. | ||
| + | < | ||
| + | docker run -e DISPLAY_NAME=YourName --name flask -p YourPort: | ||
| + | </ | ||
| + | You can check if the container is working properly by making a request to the port it uses, by listing your running containers and by checking the logs of the container. | ||
| + | < | ||
| + | curl localhost: | ||
| + | docker ps | ||
| + | docker logs flask | ||
| + | </ | ||
| + | Then stop and remove the container. Note that docker does not automatically remove stopped containers, you can see stopped containers with //docker ps -a//. | ||
| + | < | ||
| + | docker stop flask && docker rm flask | ||
| + | </ | ||
| + | === Configure your container with Compose === | ||
| + | Make sure your current container is stopped, then edit the // | ||
| + | docker-compose up -d | ||
| + | The //-d// flag detaches the container output from your terminal window. Check the output from the container with //curl localhost: | ||
| + | < | ||
| + | Curl the port again - it should have changed. Stop your container again with // | ||
| + | === Extra tasks to look into === | ||
| + | * Look into mounting and accessing a volume with Compose | ||
| + | * Open a shell in the container with //docker exec -it flask(-compose) sh// | ||
| + | * Try finding a docker image online and adding it as a service | ||
| + | * Find a piece of self-hosted software you can run as a Docker container | ||
howto/specific/learndocker.1737031293.txt.gz · Last modified: 2025/01/16 12:41 by alexdavis
