Changes between Version 3 and Version 4 of dockerdeployment2023
- Timestamp:
- Nov 28, 2023, 5:07:01 AM (12 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
dockerdeployment2023
v3 v4 4 4 1. Update Your System: Ensure your system package database is up-to-date. 5 5 6 $ sudo apt update 7 $ sudo apt upgrade 6 `$ sudo apt update ` 7 8 `$ sudo apt upgrade` 8 9 9 10 2. Install Docker: Install Docker using the convenience script provided by Docker. 10 11 11 $ curl -fsSL https://get.docker.com -o get-docker.sh 12 $ sudo sh get-docker.sh 12 `$ curl -fsSL https://get.docker.com -o get-docker.sh` 13 14 `$ sudo sh get-docker.sh` 13 15 14 16 3. Add User to Docker Group (Optional): If you want to run Docker commands without sudo, add your user to the docker group. 15 17 16 $ sudo usermod -aG docker ${USER} 18 `$ sudo usermod -aG docker ${USER}` 17 19 18 20 Log out and log back in for the group changes to take effect. … … 20 22 4. Start and Enable Docker: Ensure Docker starts on boot. 21 23 22 $ sudo systemctl enable docker 23 $ sudo systemctl start docker 24 `$ sudo systemctl enable docker` 25 26 `$ sudo systemctl start docker` 24 27 25 28 5. Verify Docker Installation: Check the Docker version to ensure it's installed correctly. 26 29 27 $ docker --version 30 `$ docker --version` 28 31 29 32 === 6. Deploying a Sample Web Application using Docker === … … 31 34 6.1 Pull a Sample Web Application Image: For this guide, we'll use a simple HTTP server image from Docker Hub. 32 35 33 $ docker pull httpd 36 `$ docker pull httpd` 34 37 35 38 6.2 Run the Web Application: Start a container using the httpd image. This will run the web server on port 8080. 36 39 37 $ docker run -d -p 8080:80 --name sample-webapp httpd 40 `$ docker run -d -p 8080:80 --name sample-webapp httpd` 38 41 39 42 6.3 Access the Web Application: If you're accessing the server locally, open a web browser and navigate to: (Since you are connected via SSH lets install a text-based web browser lynx.) 40 43 41 $ sudo apt-get install lynx 42 $ lynx http://localhost:8080 44 `$ sudo apt-get install lynx` 45 46 `$ lynx http://localhost:8080` 43 47 44 48 6.4 Stop and Remove the Web Application (Optional): 45 49 When you're done testing the web application, you can stop and remove the container. 46 50 47 $ docker stop sample-webapp 48 $ docker rm sample-webapp 51 `$ docker stop sample-webapp` 52 53 `$ docker rm sample-webapp` 49 54 50 55 Extra Ref: … … 55 60 Basic Docker Commands and Their Usage 56 61 57 • docker --version62 • ` docker --version` 58 63 Usage: Displays the Docker version installed. 59 Example: docker --version60 61 • docker info64 Example: `docker --version` 65 66 • `docker inf`o 62 67 Usage: Provides detailed information about the Docker installation. 63 Example: docker info64 65 • docker pull <image_name>68 Example:` docker info` 69 70 • `docker pull <image_name>` 66 71 Usage: Downloads a Docker image from Docker Hub. 67 Example: docker pull nginx68 69 • docker build -t <image_name>:<tag> <path>72 Example: `docker pull nginx` 73 74 • `docker build -t <image_name>:<tag> <path>` 70 75 Usage: Builds a Docker image from a Dockerfile located at <path>. 71 76 Example: docker build -t myapp:latest . 72 77 73 • docker images78 • ` docker images` 74 79 Usage: Lists all available Docker images on the system. 75 Example: docker images76 77 • docker run <options> <image_name>80 Example:` docker images` 81 82 • `docker run <options> <image_name>` 78 83 Usage: Creates and starts a container from a Docker image. 79 Example: docker run -d -p 80:80 nginx80 81 • docker ps84 Example: `docker run -d -p 80:80 nginx` 85 86 • `docker ps` 82 87 Usage: Lists running containers. 83 Example: docker ps84 85 • docker ps -a88 Example:` docker ps` 89 90 • ` docker ps -a` 86 91 Usage: Lists all containers, including stopped ones. 87 Example: docker ps -a88 89 • docker stop <container_id/container_name>92 Example: `docker ps -a` 93 94 • `docker stop <container_id/container_name>` 90 95 Usage: Stops a running container. 91 Example: docker stop my_container92 93 • docker rm <container_id/container_name>96 Example: `docker stop my_container` 97 98 • `docker rm <container_id/container_name>` 94 99 Usage: Removes a stopped container. 95 Example: docker rm my_container96 97 • docker rmi <image_name>100 Example: `docker rm my_container` 101 102 • ` docker rmi <image_name>` 98 103 Usage: Removes a Docker image. 99 Example: docker rmi nginx100 101 • docker logs <container_id/container_name>104 Example: `docker rmi nginx` 105 106 • `docker logs <container_id/container_name>` 102 107 Usage: Displays logs from a running or stopped container. 103 Example: docker logs my_container108 Example: `docker logs my_container` 104 109 105 110 Troubleshooting Common Docker Container Issues