Changes between Version 6 and Version 7 of dockerdeployment2023


Ignore:
Timestamp:
Dec 4, 2023, 4:34:47 AM (12 months ago)
Author:
deepthi
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • dockerdeployment2023

    v6 v7  
    127127
    128128        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.
    131131
    132132•           Container Performance Issues
    133133
    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.
     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.
    137137
    138138•           Image-Related Issues
    139139
    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>`.
    141141        Check Dockerfile: If you're building your own image, ensure that the Dockerfile has the correct instructions.
    142142
     
    144144
    145145        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 --user Flag: 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.
    147147 
    148148 
     
    157157A 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.
    158158
    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.
    162162        Example: `FROM ubuntu:20.04`
    163163
    164     LABEL: Adds metadata to the image, like maintainer information.
     164    `LABEL`: Adds metadata to the image, like maintainer information.
    165165        Example: `LABEL maintainer="name@example.com"`
    166166
    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.
    168168        Example: `RUN apt-get update && apt-get install -y nginx`
    169169
    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.
    171171        Example:` CMD ["nginx", "-g", "daemon off;"]`
    172172
    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.
    174174        Example: `ENTRYPOINT ["nginx"]`
    175175
    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.
    177177        Example: `COPY ./webapp /var/www/webapp`
    178178
    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.
    180180        Example: `ADD https://example.com/app.tar.gz /app/`
    181181
    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.
    183183        Example: `WORKDIR /app`
    184184
    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.
    186186        Example: `EXPOSE 80`
    187187
    188     ENV: Sets environment variables.
     188    `ENV`: Sets environment variables.
    189189        Example: `ENV MY_VARIABLE=value`
    190190
    191     VOLUME: Creates a mount point for external storage or other containers.
     191    `VOLUME`: Creates a mount point for external storage or other containers.
    192192        Example: `VOLUME /data`
    193193 
    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
     196First, create a folder called `my-webserver` and go inside it `cd my-webserver`
     197
    197198Then create another folder inside that called website and a file called index.html within the folder website with any content of your choice.
    198199 
    199200Create a file dockerfile with the following content within the my-webserver folder.
    200201 
     202{{{
    201203# Use the official Nginx image as a base
    202 `FROM nginx:latest`
     204FROM nginx:latest
    203205
    204206# Set the maintainer label
    205 `LABEL maintainer="name@example.com"`
     207LABEL maintainer="name@example.com"
    206208
    207209# Copy static website files to the Nginx web directory
    208 `COPY ./website /usr/share/nginx/html`
     210COPY ./website /usr/share/nginx/html
    209211
    210212# Expose port 80 for the web server
    211 `EXPOSE 80`
     213EXPOSE 80
    212214
    213215# Default command to run Nginx in the foreground
    214 `CMD ["nginx", "-g", "daemon off;"]`
    215 
    216 
    217 Building an Image from a Dockerfile
     216CMD ["nginx", "-g", "daemon off;"]
     217}}}
     218
     219===== Building an Image from a Dockerfile =====
    218220
    219221To build a Docker image from your Dockerfile, navigate to the directory containing the Dockerfile and run:
     
    221223`docker build -t my-webserver:latest .`
    222224
    223 This command tells Docker to build an image using the Dockerfile in the current directory (.) and tag it as my-webserver:latest.
     225This command tells Docker to build an image using the Dockerfile in the current directory (.) and tag it as `my-webserver:latest`.
    224226 
    225227Best Practices
     
    232234=== Part 3: ===
    233235
    234 What is Docker Compose?
     236'''What is Docker Compose?'''
    235237
    236238Docker 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).
    237239
    238 Key Concepts
     240'''Key Concepts'''
    239241
    240242    Services: Each container started by Docker Compose is a service. Services are defined in the docker-compose.yml file.
     
    242244    Volumes: Volumes can be used to share files between the host and container or between containers.
    243245 
    244 Basic docker-compose Commands
     246'''Basic docker-compose Commands'''
    245247
    246248•          ` docker-compose up`: Starts up the services defined in the docker-compose.yml file.
     
    249251•          `docker-compose logs`: Shows the logs from the services.
    250252 
    251 Deploying WordPress with Docker Compose
     253'''Deploying WordPress with Docker Compose'''
    252254
    253255Let's deploy a WordPress application using two containers: one for WordPress and another for the MySQL database.
    254256Create a docker-compose.yml file:
     257
     258{{{
    255259version: '3'
    256260
     
    285289    db_data: {}
    286290    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
     293Start the WordPress and Database Containers: Navigate to the directory containing the `docker-compose.yml` file and run:
     294
     295`docker-compose up -d`
     296
    292297This 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.
    293298 
     
    306311==== Part 4: ====
    307312
    308 Deploy any web app as per your wish and showcase its usage of it. You need to use more than one docker container
     313Deploy any web app as per your wish and showcase its usage of it.''' You need to use more than one docker container'''
    309314
    310315eg: you can use three containers, one to run a web app and the others to run a database and other data storage respectively.