Giter Site home page Giter Site logo

wordpres_nginx_docker's Introduction

Dockerfile

Use the Ubuntu base image

FROM ubuntu:latest

Set non-interactive mode for package installations

ARG DEBIAN_FRONTEND=noninteractive

Update the package lists, install NGINX, and add the PHP repository

RUN apt-get update &&
apt-get install -y nginx software-properties-common &&
add-apt-repository ppa:ondrej/php

RUN apt-get install -y curl

Install PHP and its extensions

RUN apt-get update &&
apt-get install -y
php8.1
php8.1-fpm
php8.1-cli
php8.1-common
php8.1-mysql
php8.1-gd
php8.1-curl
php8.1-xml
php8.1-bcmath

Expose port 80

EXPOSE 80

Copy NGINX site configuration

COPY ./nginx/sites-available/default /etc/nginx/sites-available/default

Copy your web content to the NGINX document root

COPY . /var/www/html

Start PHP-FPM and NGINX

CMD service php8.1-fpm start && nginx -g 'daemon off;'

Building the Docker Image

You can create the Docker image using the following command:

docker build -t wordpress_nginx:latest .

If you want to build the Docker image without utilizing the cache, you can use the following command:

docker build -t wordpress_nginx:latest --no-cache .

Run a Docker container with a specific name, detached mode, and port mapping

docker run --name some-nginx-01 -it -d -p 127.0.0.1:2124:80 wordpress_nginx:latest

Push the Docker Image to Docker Hub

Tag a Docker image with a new name and version

docker tag wordpress_nginx bamalik1996/wordpress_nginx:1.0

Push a Docker image to a container registry

docker push bamalik1996/wordpress_nginx:1.0

Pulls a Docker image for WordPress with Nginx from 'bamalik1996'.

docker pull bamalik1996/wordpress_nginx

Use Different Docker Container Commands

List running Docker containers

docker ps

CONTAINER ID | IMAGE | COMMAND | CREATED | STATUS | PORTS | NAMES |


32ed12171f92 | b6a588413b51 | "/bin/sh -c 'service…" | 2 days ago | Up About an hour | 127.0.0.1:2124->80/tcp | some-nginx-03 |

Stop running Docker containers

docker stop CONTAINER ID
docker stop 32ed12171f92 

Remove stop Docker containers

docker rm CONTAINER ID
docker rm 32ed12171f92 

Inspect Docker containers

docker inspect CONTAINER ID
docker inspect 32ed12171f92 
[
    {
        "Id": "ff8b740a635c3fbc2b4d31a83388f7c46ae6b40c0604a53ff1f98c914d219501",
        "Created": "2023-11-02T06:28:22.638830408Z",
        "Path": "/bin/sh",
        "Args": [
            "-c",
            "service php8.1-fpm start \u0026\u0026 nginx -g 'daemon off;'"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 13503,
            "ExitCode": 0
        }.....

Inspect Docker containers

docker exec -it [Container ID or Container Name] command 
docker exec -it some-nginx-03 tail -f /var/log/nginx/access.log 

Create a new image from a Docker Container

docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]
docker commit  some-nginx-03 wordpress_nginx:v1 

Response

sha256:3ffd87c8a0482b5665115803e3979030911af711ce121ad5d12e5c7835b93654

Command to copy files/folders between the container and the host

docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH
docker cp some-nginx-02:/etc/nginx/sites-available/default ./nginx/sites-available/default
docker cp ./nginx/sites-available/default some-nginx-02:/etc/nginx/sites-available/default

Command to view the resource usage of containers

docker stats [Container ID]
docker stats ff8b740a635c3fbc2b4d31a83388f7c46ae6b40c0604a53ff1f98c914d219501
CONTAINER IDNAMECPU %MEM USAGE / LIMITMEM %NET I/OBLOCK I/OPIDS
ff8b740a635csome-nginx-030.01%21.1MiB / 7.682GiB0.27%806B / 0B0B / 0B13

Command to view the running processes inside a container

docker top [Container ID]
docker top ff8b740a635c3fbc2b4d31a83388f7c46ae6b40c0604a53ff1f98c914d219501
UIDPIDPPIDCSTIMETTYTIMECMD
www-data28582857019:38?00:00:00php-fpm: pool www
www-data28592857019:38?00:00:00php-fpm: pool www
root28602827019:38?00:00:00nginx: master process nginx -g daemon off

Command to start a stopped container

docker start [Container ID]
docker start ff8b740a635c3fbc2b4d31a83388f7c46ae6b40c0604a53ff1f98c914d219501

Command to pause a running container

docker stop [Container ID]
docker stop ff8b740a635c3fbc2b4d31a83388f7c46ae6b40c0604a53ff1f98c914d219501

Command to unpause a paused container

docker stop [Container ID]
docker stop ff8b740a635c3fbc2b4d31a83388f7c46ae6b40c0604a53ff1f98c914d219501

Command to unpause a paused container

docker rename CONTAINER NEW_NAME
docker rename ff8b740a635c3fbc2b4d31a83388f7c46ae6b40c0604a53ff1f98c914d219501 some-nginx-rename

Command to wait for a container to exit and then display its exit code

docker wait CONTAINER ID
docker wait ff8b740a635c3fbc2b4d31a83388f7c46ae6b40c0604a53ff1f98c914d219501

Command to display the public-facing port that a container is listening on

docker port CONTAINER ID
docker port ff8b740a635c3fbc2b4d31a83388f7c46ae6b40c0604a53ff1f98c914d219501

Response

80/tcp -> 127.0.0.1:2124

Command to update a container's resource limits

docker update [OPTIONS] CONTAINER [CONTAINER...]
docker update --cpu-shares 512 ff8b740a635c3fbc2b4d31a83388f7c46ae6b40c0604a53ff1f98c914d219501

Command to restart a running container

docker restart [CONTAINER ID]
docker restart ff8b740a635c3fbc2b4d31a83388f7c46ae6b40c0604a53ff1f98c914d219501

wordpres_nginx_docker's People

Contributors

bamalik1996 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.