Changes between Version 4 and Version 5 of dockerdeployment2023
- Timestamp:
- Nov 28, 2023, 5:14:19 AM (12 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
dockerdeployment2023
v4 v5 157 157 158 158 FROM: Specifies the base image to start from. It's usually an OS or another application. 159 Example: FROM ubuntu:20.04159 Example: `FROM ubuntu:20.04` 160 160 161 161 LABEL: Adds metadata to the image, like maintainer information. 162 Example: LABEL maintainer="name@example.com"162 Example: `LABEL maintainer="name@example.com"` 163 163 164 164 RUN: Executes commands in a new layer on top of the current image and commits the result. 165 Example: RUN apt-get update && apt-get install -y nginx165 Example: `RUN apt-get update && apt-get install -y nginx` 166 166 167 167 CMD: Provides defaults for the executing container. There can only be one CMD instruction in a Dockerfile. 168 Example: CMD ["nginx", "-g", "daemon off;"]168 Example:` CMD ["nginx", "-g", "daemon off;"]` 169 169 170 170 ENTRYPOINT: Configures the container to run as an executable. It's often used in combination with CMD. 171 Example: ENTRYPOINT ["nginx"]171 Example: `ENTRYPOINT ["nginx"]` 172 172 173 173 COPY: Copies files or directories from the host machine to the container. 174 Example: COPY ./webapp /var/www/webapp174 Example: `COPY ./webapp /var/www/webapp` 175 175 176 176 ADD: Similar to COPY, but can also handle URLs and tarball extraction. 177 Example: ADD https://example.com/app.tar.gz /app/178 179 WORKDIR: Sets the working directory for any subsequent RUN, CMD, ENTRYPOINT, COPY, and ADDinstructions.180 Example: WORKDIR /app177 Example: `ADD https://example.com/app.tar.gz /app/` 178 179 WORKDIR: Sets the working directory for any subsequent `RUN`, `CMD`, `ENTRYPOINT`,` COPY`, and `ADD` instructions. 180 Example: `WORKDIR /app` 181 181 182 182 EXPOSE: Informs Docker that the container listens on the specified network port at runtime. 183 Example: EXPOSE 80183 Example: `EXPOSE 80` 184 184 185 185 ENV: Sets environment variables. 186 Example: ENV MY_VARIABLE=value186 Example: `ENV MY_VARIABLE=value` 187 187 188 188 VOLUME: Creates a mount point for external storage or other containers. 189 Example: VOLUME /data189 Example: `VOLUME /data` 190 190 191 191 Let's create a Dockerfile for a basic web server using Nginx: … … 197 197 198 198 # Use the official Nginx image as a base 199 FROM nginx:latest 199 `FROM nginx:latest` 200 200 201 201 # Set the maintainer label 202 LABEL maintainer="name@example.com" 202 `LABEL maintainer="name@example.com"` 203 203 204 204 # Copy static website files to the Nginx web directory 205 COPY ./website /usr/share/nginx/html 205 `COPY ./website /usr/share/nginx/html` 206 206 207 207 # Expose port 80 for the web server 208 EXPOSE 80 208 `EXPOSE 80` 209 209 210 210 # Default command to run Nginx in the foreground 211 CMD ["nginx", "-g", "daemon off;"] 211 `CMD ["nginx", "-g", "daemon off;"]` 212 212 213 213 … … 215 215 216 216 To build a Docker image from your Dockerfile, navigate to the directory containing the Dockerfile and run: 217 docker build -t my-webserver:latest . 217 218 `docker build -t my-webserver:latest .` 219 218 220 This command tells Docker to build an image using the Dockerfile in the current directory (.) and tag it as my-webserver:latest. 219 221 … … 239 241 Basic docker-compose Commands 240 242 241 • docker-compose up: Starts up the services defined in the docker-compose.yml file.242 • docker-compose down: Stops and removes all the containers defined in the docker-compose.yml file.243 • docker-compose ps: Lists the services and their current state (running/stopped).244 • docker-compose logs: Shows the logs from the services.243 • ` docker-compose up`: Starts up the services defined in the docker-compose.yml file. 244 • ` docker-compose down`: Stops and removes all the containers defined in the docker-compose.yml file. 245 • ` docker-compose ps`: Lists the services and their current state (running/stopped). 246 • `docker-compose logs`: Shows the logs from the services. 245 247 246 248 Deploying WordPress with Docker Compose … … 285 287 286 288 docker-compose up -d 287 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>:8080from your browser.289 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. 288 290 289 291 Stopping the Services: To stop the services, navigate to the same directory and run: 290 292 291 docker-compose down 293 `docker-compose down` 292 294 293 295 Best Practices 294 296 • Explicit Service Names: Give your services explicit names to make it clear what each service does. 297 295 298 • Environment Variables: Use environment variables for sensitive information and configurations. 299 296 300 • Service Dependencies: Use the depends_on option to ensure services start in the correct order. 297 301 … … 299 303 ==== Part 4: ==== 300 304 301 Deploy any web app as per your wish and showcase its usage of it. You need to use more than one docker container eg: you can use three containers, one to run a web app and the others to run a database and other data storage respectively. You may use the docker hub to get any existing containers. What we evaluate is your ability to deploy the containers and bringing up a working web app. 305 Deploy any web app as per your wish and showcase its usage of it. You need to use more than one docker container 306 307 eg: you can use three containers, one to run a web app and the others to run a database and other data storage respectively. 308 You may use the docker hub to get any existing containers. What we evaluate is your ability to deploy the containers and bringing up a working web app.