DEV Community

Muhamad Jamil
Muhamad Jamil

Posted on

My first time using docker for deploying static website

im using AWS EC2 for VPS, Ubuntu 20.04 for operating system, and nginx as a web server.

First we need to install the docker
maybe you want to read more in their documentation

or using my method, step by step install docker

login as root

  1. apt -y update
  2. apt -y install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
  3. 'curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  4. apt-key fingerprint 0EBFCD88
  5. add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  6. apt -y update
  7. apt -y install docker-ce docker-ce-cli containerd.io

and for checking the docker running
systemctl status docker

after the docker installation, choose your static website that you want to deploy.

after that, create a Dockerfile

nano Dockerfile

inside the Dockerfile type this

# Choose the image
FROM nginx
# Remove the default file
RUN rm -rf /usr/share/nginx/html/*
# Copy and move your own website file to the nginx html folder
COPY ./{your directory website} /usr/share/nginx/html
Enter fullscreen mode Exit fullscreen mode

its time to build your image
docker build -t {image name} .

for example
docker build -t theia .

and to check if your image build success
docker images

REPOSITORY   TAG       IMAGE ID       CREATED          SIZE
theia        latest    b8b7870c8621   24 minutes ago   143MB
nginx        latest    0e901e68141f   11 days ago      142MB
Enter fullscreen mode Exit fullscreen mode

if you see your docker image, now were gonna run it

docker run -d(for running in background) -p 8080:80(choose your not used port) --name(name your container) (your image)

for example

docker run -d -p 8080:80 --name thalia theia

and finally you can access your website using your public ip and port

example mine is 54.183.74.95:8080

if you have another method, feel free to discuss.
thanks for reading, have a nice day

Top comments (0)