Skip to content

Instantly share code, notes, and snippets.

@trulymittal
Last active September 20, 2023 04:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save trulymittal/c4912a473231c611c8b7629377310bc7 to your computer and use it in GitHub Desktop.
Save trulymittal/c4912a473231c611c8b7629377310bc7 to your computer and use it in GitHub Desktop.

Running Nginx container using Docker

To start setting up Nginx container

Step 1: Pull the latest image from docker hub (https://hub.docker.com)

docker pull nginx

Step 2: Create a new directory on your machine from where you want to serve the html files.

mkdir nginx-html

Step 3: cd into that directory

cd nginx-html

Step 4: Create index.html and whatever files you like, using any text editor.

Step 5: Run this command to start the container

docker run -d -p 8000:80 -v /YOUR_HTML_FILES_ABSOLUTE_DIRECTORY_PATH:/usr/share/nginx/html --name my-nginx-container nginx

To stop the container

docker stop my-nginx-container

To start the container again

docker start my-nginx-container

To remove the stopped container

docker rm my-nginx-container

To remove the running container

docker rm my-nginx-container -f

Authors

License

This project is licensed under the MIT License.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment