Configuring_Docker_Containers.docx

Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Full Transcript

Introduction ============ Lab Overview ------------ 1. In the first part of the lab, you will create a Docker image and a Docker container and then run the container. 2. In the second part of the lab, you will create and run an application that uses two images that work together. 3. I...

Introduction ============ Lab Overview ------------ 1. In the first part of the lab, you will create a Docker image and a Docker container and then run the container. 2. In the second part of the lab, you will create and run an application that uses two images that work together. 3. In the third part of the lab, you will define and run your multi-container application using the Docker Compose tool. Learning Objectives ------------------- 1. Explain the difference between containerization and virtualization. 2. Build and run Docker containers using the command line. 3. Configure a Docker image using a Dockerfile. 4. Use the Docker command line to manage networks. 5. Use Docker Compose to manage a multi-container application. Topology -------- Tools and Software ------------------ Deliverables ------------ 1. Lab Report file, including screen captures of the following: 2. Any additional information as directed by the lab: 1. Lab Report file, including screen captures of the following: 2. Any additional information as directed by the lab: Hands-On Demonstration ====================== 1. **Review** the **Tutorial**. 2. **Proceed** with **Part 1**. Part 1: Creating and Running a Docker Container ----------------------------------------------- 1. If necessary, on the Ubuntu-Desktop login screen, **type the following credentials** and **press Enter** to log in. 2. On the sidebar, **click** the **Terminal icon** to open a new terminal. ![](media/image4.jpeg) Terminal Icon 3. In the terminal, **type cd test** and **press Enter** to change the current directory. 4. In the terminal, **type cat Dockerfile** and **press Enter** to see the contents of the Dockerfile. Dockerfile contents 5. In the terminal, **type sudo docker build \--tag test.** and **press Enter** to attempt to build the image using the Dockerfile. **Type password** and **press Enter** if asked for the sudo password. ![](media/image6.jpeg) Command to build test image 6. In the terminal, **type ls** and **press Enter** to list the files. 7. In the terminal, **type echo \"example file content\" \>file\_1.txt** and **press Enter** to create the file. 8. In the terminal, **type sudo docker build \--tag test.** and **press Enter** to build the image. 9. **Make a screen capture** showing the **successful build of the test image**. 10. In the terminal, **type sudo docker image ls** and **press Enter** to list the images that are available. 11. In the terminal, **type sudo docker image inspect test** and **press Enter** to show detailed information about the test. Command to inspect the test image 12. In the terminal, **type sudo docker container create -it \--name testc test** and Command to create the test container 13. In the terminal, **type sudo docker container ls \--all** and **press Enter** to list the containers. 14. In the terminal, **type sudo docker container inspect testc** and **press Enter** to view details about the container. ![](media/image9.jpeg) Command to inspect the test container 15. In the terminal, **type sudo docker container start -i testc** and **press Enter** to start the container. Command to start the test container 16. In the terminal, **type pwd** and **press Enter** to see the working directory. 17. In the terminal, **type ls** and **press Enter** to list the files. 18. In the terminal, **type echo \$EXAMPLEVAR** and **press Enter** to check for the environment variable. 19. **Make a screen capture** showing the **working directory, file listing, and environment variable value**. 20. In the terminal, **type exit** and **press Enter** to exit the container shell. 21. In the terminal, **type sudo docker container ls \--all** and **press Enter** to list all 22. In the terminal, **type sudo docker container rm testc** and **press Enter** to remove the testc container. 23. In the terminal, **type sudo docker container ls \--all** and **press Enter** to verify that the container no longer exists. 24. In the terminal, **type sudo docker run -it \--name testc test** and **press Enter** to run the container. Command to create and run a container 25. In the terminal, **type cat file\_1.txt** to output the content of file\_1.txt to the terminal. 26. **Make a screen capture** showing **both your docker run command and the contents of the file\_1.txt**. 27. **Exit** the container. Part 2: Configuring an Application with Multiple Containers ----------------------------------------------------------- 1. In the terminal on Ubuntu-Desktop, **type curl http://registry:5000/v2/\_catalog** Command to get the list of images from the registry 2. In the terminal, **type cd \~/db** and **press Enter** to change the working directory. 3. In the terminal, **type cat Dockerfile** and **press Enter** to view the Dockerfile. ![](media/image13.png) Command to view the Dockerfile 4. In the terminal, **type sudo docker build -t db.** and **press Enter** to create the image and tag it. Command to build the image 5. In the terminal, **type sudo docker run -d \--name db -v** Comamnd to create and run the container 6. In the terminal, **type sudo docker ps** and **press Enter** to list the running containers. 7. **Make a screen capture** showing **the running db container**. 8. In the terminal, **type cd \~/web** and **press Enter** to change the working directory. 9. In the terminal, **type cat Dockerfile** and **press Enter** to view the Dockerfile contents. Command to view the Dockerfile 10. In the terminal, **type sudo docker build -t web.** and **press Enter** to build the Docker image. Command to create the image 11. In the terminal, **type sudo docker run \--rm -v \$(pwd)/code:/code web django- admin startproject example.** and **press Enter** to initialize the Django app. ![](media/image19.png) Command to create and run the container and initialize the app 12. In the terminal, **type sudo docker container ls \--all** and **press Enter** to see the list of running containers. 13. In the terminal, **type ls -al code** and **press Enter** to view the code directory files. 14. In the terminal, **type sudo chown -R user:user code** and **press Enter** to change the ownership of all the files in the tree. 15. In the terminal, **type vim code/example/settings.py** and **press Enter** to open the app settings file in an editor. 16. In the editor, **add the following line** after the line \"from pathlib import Path\": 17. In the editor, **update the databases section** to match the following: 18. In the terminal, **type sudo docker run \--rm -p 8000:8000 -v \$(pwd)/code:/code web python manage.py runserver 0.0.0.0:8000** and **press Enter** to try to launch the application. Command to create and run the web container 19. In the terminal, **press ctrl-c** to stop and remove the web container. 20. In the terminal, **type sudo docker container stop db** and **press Enter** to stop the db container. 21. In the terminal, **type sudo docker container rm db** and **press Enter** to remove the db container. 22. In the terminal, **type sudo docker network create \--driver bridge app-net** and ![](media/image21.png) Command to create a network 23. In the terminal, **type sudo docker network ls** and **press Enter** to list the docker networks. 24. **Make a screen capture** showing the **command creating the network and the resulting id**. 25. In the terminal, **type sudo docker run -d \--name db \--network app-net -v** Command to create and run the db container 26. In the terminal, **type sudo docker run -d \--name web \--network app-net -p 8000:8000 -v /home/user/web/code:/code web python manage.py runserver 0.0.0.0:8000** and **press Enter** to run the web application image in a container. Command to create and run the web container 27. In the terminal, **type sudo docker ps** and **press Enter** to view the running containers. 28. In the sidebar, **click** the **Firefox icon** to open the web browser. Firefox Icon 29. In the browser, **navigate to localhost:8000**. ![](media/image25.png) Navigate to localhost:8000 30. **Make a screen capture** showing **the Django page**. Part 3: Using Docker Compose ---------------------------- 1. In the terminal, **type sudo docker ps -q \| xargs sudo docker stop** and **press Enter** to stop all running containers. Command to stop all containers 2. In the terminal, **type sudo docker ps -q -a \| xargs sudo docker rm** and **press Enter** to remove all the Docker containers. ![](media/image27.png) Command to remove all containers 3. In the terminal, **type cp \~/web/code/example/settings.py \~/.** and **press Enter** to copy the settings file for reuse. 4. In the terminal, **type sudo rm -rf \~/web/code** and **press Enter** to remove the application files created in Part 2. 5. In the terminal, **type sudo rm -rf \~/db/data** and **press Enter** to remove the database files from Part 2. 6. In the terminal, **type cd \~/app** and **press Enter** to change the working directory. 7. In the terminal, **type cat docker-compose.yml** and **press Enter** to view the YAML file. Command to view the Docker compose file 8. In the terminal, **type sudo docker compose run web django-admin startproject example.** and **press Enter** to initialize the Django application. Command to initialize the web app 9. In the terminal, **type sudo cp \~/settings.py \~/web/code/example/settings.py** 10. In the terminal, **type sudo docker compose up** and **press Enter** to start all the containers needed for the application. 11. **Make a screen capture** showing **output from the compose up command**. 12. In the web browser, **navigate to localhost:8000** to confirm that the application is running. 13. **Restore** the terminal and **press ctrl-c** to stop and remove the web container. Challenge and Analysis ====================== Part 1: Create an Image to Serve a Static File ---------------------------------------------- Part 2: Add the Static Service to the Docker Compose File ---------------------------------------------------------

Use Quizgecko on...
Browser
Browser