Changes between Version 6 and Version 7 of dockerdeployment2023
- Timestamp:
- Dec 4, 2023, 4:34:47 AM (12 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
dockerdeployment2023
v6 v7 127 127 128 128 Check Volumes: Ensure that directories or files from the host are correctly mounted into the container using the -v option. 129 You may use docker volume ls to list all volumes mapped and docker volume inspect <volume_name>to inspect a selected volume.130 Inspect Image: Use docker image inspect <image_name>to see the image's layers and ensure the required files are present.129 You may use `docker volume ls` to list all volumes mapped and `docker volume inspect <volume_name>` to inspect a selected volume. 130 Inspect Image: Use `docker image inspect <image_name>` to see the image's layers and ensure the required files are present. 131 131 132 132 • Container Performance Issues 133 133 134 Check Resources: Containers might face performance issues if they're not allocated enough resources. Use docker statsto check the resource usage of running containers.135 Limit Resources: When running a container, you can use flags like --cpus and --memoryto limit its resources.136 You can use docker top <container_name>to see some stats.134 Check Resources: Containers might face performance issues if they're not allocated enough resources. Use `docker stats` to check the resource usage of running containers. 135 Limit Resources: When running a container, you can use flags like `--cpus` and `--memory` to limit its resources. 136 You can use `docker top <container_name>` to see some stats. 137 137 138 138 • Image-Related Issues 139 139 140 Pull Latest Image: Ensure you have the latest version of the image using docker pull <image_name>.140 Pull Latest Image: Ensure you have the latest version of the image using `docker pull <image_name>`. 141 141 Check Dockerfile: If you're building your own image, ensure that the Dockerfile has the correct instructions. 142 142 … … 144 144 145 145 User Mappings: If a containerized application can't access certain files, it might be a user permission issue. Ensure that the user inside the container has the necessary permissions. 146 Use --userFlag: When running a container, you can specify which user the container should run as using the --user flag.146 Use `--user` Flag: When running a container, you can specify which user the container should run as using the --user flag. 147 147 148 148 … … 157 157 A Dockerfile consists of a series of instructions and arguments. Each instruction is an operation used to build the image, like installing a software package or copying files. The instruction is written in uppercase, followed by its arguments. 158 158 159 Key Dockerfile Instructions 160 161 FROM: Specifies the base image to start from. It's usually an OS or another application.159 ==== Key Dockerfile Instructions ==== 160 161 `FROM`: Specifies the base image to start from. It's usually an OS or another application. 162 162 Example: `FROM ubuntu:20.04` 163 163 164 LABEL: Adds metadata to the image, like maintainer information.164 `LABEL`: Adds metadata to the image, like maintainer information. 165 165 Example: `LABEL maintainer="name@example.com"` 166 166 167 RUN: Executes commands in a new layer on top of the current image and commits the result.167 `RUN`: Executes commands in a new layer on top of the current image and commits the result. 168 168 Example: `RUN apt-get update && apt-get install -y nginx` 169 169 170 CMD: Provides defaults for the executing container. There can only be one CMD instruction in a Dockerfile.170 `CMD`: Provides defaults for the executing container. There can only be one CMD instruction in a Dockerfile. 171 171 Example:` CMD ["nginx", "-g", "daemon off;"]` 172 172 173 ENTRYPOINT: Configures the container to run as an executable. It's often used in combination with CMD.173 `ENTRYPOINT`: Configures the container to run as an executable. It's often used in combination with CMD. 174 174 Example: `ENTRYPOINT ["nginx"]` 175 175 176 COPY: Copies files or directories from the host machine to the container.176 `COPY`: Copies files or directories from the host machine to the container. 177 177 Example: `COPY ./webapp /var/www/webapp` 178 178 179 ADD: Similar to COPY, but can also handle URLs and tarball extraction.179 `ADD`: Similar to COPY, but can also handle URLs and tarball extraction. 180 180 Example: `ADD https://example.com/app.tar.gz /app/` 181 181 182 WORKDIR: Sets the working directory for any subsequent `RUN`, `CMD`, `ENTRYPOINT`,` COPY`, and `ADD` instructions.182 `WORKDIR`: Sets the working directory for any subsequent `RUN`, `CMD`, `ENTRYPOINT`,` COPY`, and `ADD` instructions. 183 183 Example: `WORKDIR /app` 184 184 185 EXPOSE: Informs Docker that the container listens on the specified network port at runtime.185 `EXPOSE`: Informs Docker that the container listens on the specified network port at runtime. 186 186 Example: `EXPOSE 80` 187 187 188 ENV: Sets environment variables.188 `ENV`: Sets environment variables. 189 189 Example: `ENV MY_VARIABLE=value` 190 190 191 VOLUME: Creates a mount point for external storage or other containers.191 `VOLUME`: Creates a mount point for external storage or other containers. 192 192 Example: `VOLUME /data` 193 193 194 Let's create a Dockerfile for a basic web server using Nginx: 195 196 First, create a folder called my-webserver and go inside it cd my-webserver 194 ===== Let's create a Dockerfile for a basic web server using Nginx: ===== 195 196 First, create a folder called `my-webserver` and go inside it `cd my-webserver` 197 197 198 Then create another folder inside that called website and a file called index.html within the folder website with any content of your choice. 198 199 199 200 Create a file dockerfile with the following content within the my-webserver folder. 200 201 202 {{{ 201 203 # Use the official Nginx image as a base 202 `FROM nginx:latest` 204 FROM nginx:latest 203 205 204 206 # Set the maintainer label 205 `LABEL maintainer="name@example.com"` 207 LABEL maintainer="name@example.com" 206 208 207 209 # Copy static website files to the Nginx web directory 208 `COPY ./website /usr/share/nginx/html` 210 COPY ./website /usr/share/nginx/html 209 211 210 212 # Expose port 80 for the web server 211 `EXPOSE 80` 213 EXPOSE 80 212 214 213 215 # Default command to run Nginx in the foreground 214 `CMD ["nginx", "-g", "daemon off;"]` 215 216 217 Building an Image from a Dockerfile 216 CMD ["nginx", "-g", "daemon off;"] 217 }}} 218 219 ===== Building an Image from a Dockerfile ===== 218 220 219 221 To build a Docker image from your Dockerfile, navigate to the directory containing the Dockerfile and run: … … 221 223 `docker build -t my-webserver:latest .` 222 224 223 This command tells Docker to build an image using the Dockerfile in the current directory (.) and tag it as my-webserver:latest.225 This command tells Docker to build an image using the Dockerfile in the current directory (.) and tag it as `my-webserver:latest`. 224 226 225 227 Best Practices … … 232 234 === Part 3: === 233 235 234 What is Docker Compose? 236 '''What is Docker Compose?''' 235 237 236 238 Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you can define a multi-container application in a single file, then spin up your application with a single command (docker-compose up). 237 239 238 Key Concepts 240 '''Key Concepts''' 239 241 240 242 Services: Each container started by Docker Compose is a service. Services are defined in the docker-compose.yml file. … … 242 244 Volumes: Volumes can be used to share files between the host and container or between containers. 243 245 244 Basic docker-compose Commands 246 '''Basic docker-compose Commands''' 245 247 246 248 • ` docker-compose up`: Starts up the services defined in the docker-compose.yml file. … … 249 251 • `docker-compose logs`: Shows the logs from the services. 250 252 251 Deploying WordPress with Docker Compose 253 '''Deploying WordPress with Docker Compose''' 252 254 253 255 Let's deploy a WordPress application using two containers: one for WordPress and another for the MySQL database. 254 256 Create a docker-compose.yml file: 257 258 {{{ 255 259 version: '3' 256 260 … … 285 289 db_data: {} 286 290 wordpress_data: {} 287 288 Start the WordPress and Database Containers: Navigate to the directory containing the docker-compose.yml file and run: 289 290 291 docker-compose up -d 291 }}} 292 293 Start the WordPress and Database Containers: Navigate to the directory containing the `docker-compose.yml` file and run: 294 295 `docker-compose up -d` 296 292 297 This command will start the services in detached mode. Once the services are up, you can access the WordPress site by navigating to `http://<Floating_IP>:8080` from your browser. 293 298 … … 306 311 ==== Part 4: ==== 307 312 308 Deploy any web app as per your wish and showcase its usage of it. You need to use more than one docker container313 Deploy any web app as per your wish and showcase its usage of it.''' You need to use more than one docker container''' 309 314 310 315 eg: you can use three containers, one to run a web app and the others to run a database and other data storage respectively.