Changes between Version 4 and Version 5 of dockerdeployment2023


Ignore:
Timestamp:
Nov 28, 2023, 5:14:19 AM (12 months ago)
Author:
deepthi
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • dockerdeployment2023

    v4 v5  
    157157
    158158    FROM: Specifies the base image to start from. It's usually an OS or another application.
    159         Example: FROM ubuntu:20.04
     159        Example: `FROM ubuntu:20.04`
    160160
    161161    LABEL: Adds metadata to the image, like maintainer information.
    162         Example: LABEL maintainer="name@example.com"
     162        Example: `LABEL maintainer="name@example.com"`
    163163
    164164    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 nginx
     165        Example: `RUN apt-get update && apt-get install -y nginx`
    166166
    167167    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;"]`
    169169
    170170    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"]`
    172172
    173173    COPY: Copies files or directories from the host machine to the container.
    174         Example: COPY ./webapp /var/www/webapp
     174        Example: `COPY ./webapp /var/www/webapp`
    175175
    176176    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 ADD instructions.
    180         Example: WORKDIR /app
     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 `ADD` instructions.
     180        Example: `WORKDIR /app`
    181181
    182182    EXPOSE: Informs Docker that the container listens on the specified network port at runtime.
    183         Example: EXPOSE 80
     183        Example: `EXPOSE 80`
    184184
    185185    ENV: Sets environment variables.
    186         Example: ENV MY_VARIABLE=value
     186        Example: `ENV MY_VARIABLE=value`
    187187
    188188    VOLUME: Creates a mount point for external storage or other containers.
    189         Example: VOLUME /data
     189        Example: `VOLUME /data`
    190190 
    191191Let's create a Dockerfile for a basic web server using Nginx:
     
    197197 
    198198# Use the official Nginx image as a base
    199 FROM nginx:latest
     199`FROM nginx:latest`
    200200
    201201# Set the maintainer label
    202 LABEL maintainer="name@example.com"
     202`LABEL maintainer="name@example.com"`
    203203
    204204# Copy static website files to the Nginx web directory
    205 COPY ./website /usr/share/nginx/html
     205`COPY ./website /usr/share/nginx/html`
    206206
    207207# Expose port 80 for the web server
    208 EXPOSE 80
     208`EXPOSE 80`
    209209
    210210# Default command to run Nginx in the foreground
    211 CMD ["nginx", "-g", "daemon off;"]
     211`CMD ["nginx", "-g", "daemon off;"]`
    212212
    213213
     
    215215
    216216To 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
    218220This command tells Docker to build an image using the Dockerfile in the current directory (.) and tag it as my-webserver:latest.
    219221 
     
    239241Basic docker-compose Commands
    240242
    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.
    245247 
    246248Deploying WordPress with Docker Compose
     
    285287
    286288docker-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>:8080 from your browser.
     289This 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.
    288290 
    289291Stopping the Services: To stop the services, navigate to the same directory and run:
    290292 
    291 docker-compose down
     293`docker-compose down`
    292294 
    293295Best Practices
    294296•       Explicit Service Names: Give your services explicit names to make it clear what each service does.
     297
    295298•       Environment Variables: Use environment variables for sensitive information and configurations.
     299
    296300•       Service Dependencies: Use the depends_on option to ensure services start in the correct order.
    297301 
     
    299303==== Part 4: ====
    300304
    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.
     305Deploy any web app as per your wish and showcase its usage of it. You need to use more than one docker container
     306
     307eg: you can use three containers, one to run a web app and the others to run a database and other data storage respectively.
     308You 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.