Question

CAN'T ACCESS MY WEBSITE AFTER DEPLOY

Hi everyone,

Today I have deployed my website via digitalOcean with docker file, but I got an issue that I cant view my website (link: http://157.245.158.88:4000)

I checked my website on my local, it works fine

exp: when I type “docker run -d -p 4000:3000 ductrung/test-ci-cd:v1”, I can view my website from port 4000

I just checked log on my server and I saw my container when my web deployed it had status running, but when user go to the page container will exit and response “This site can’t be reached”,

Hope guys can help me, Thank you

extra information:

DockerFile:

 # ==== CONFIGURE =====
 # Use a Node 16 base image
 FROM node:16-alpine
 # Set the working directory to /app inside the container
 WORKDIR /app
 # Copy app files
 COPY . .
 # ==== BUILD =====
 # Install dependencies (npm ci makes sure the exact versions in the lockfile gets installed)
 RUN npm ci
 # Build the app
 RUN npm run build
 # ==== RUN =======
 # Set the env to "production"
 ENV NODE_ENV production
 # Expose the port on which the app will be running (3000 is the default that `serve` uses)
 EXPOSE 3000
 # Start the app
 CMD [ "npx", "serve", "build" ]

.gitlab-ci.yml

variables:
  IMAGE_NAME: ductrung/test-ci-cd
  IMAGE_TAG: v1

services:
  - docker:dind

stages:
  - test
  - build
  - deploy

run-tests:
  image: cypress/browsers:node18.12.0-chrome107
  stage: test
  script:
    - echo Pass test

.build:
  stage: build
  image: docker:20.10.16
  services:
    - docker:20.10.16-dind
  variables:
    DOCKER_TLS_CERTDIR: ""
  before_script:
    - echo Welcome to come new world, $USER_NAME
    - echo $IMAGE_NAME:$IMAGE_TAG
    - docker login -u $REGISTRY_USER -p $REGISTRY_PASSWORD
  script:
    - docker build -t $IMAGE_NAME:$IMAGE_TAG .
    - docker push $IMAGE_NAME:$IMAGE_TAG

build-dev:
  extends: .build
  only:
    - main

deploy_development:
  stage: deploy
  before_script:
    - chmod 400 $SSH_KEY
  script:
    - echo $SSH_KEY $HOST
    - ssh -o StrictHostKeyChecking=no -i $SSH_KEY root@157.245.158.88 "
      docker login -u $REGISTRY_USER -p $REGISTRY_PASSWORD &&
      docker run -d -p 4000:3000 $IMAGE_NAME:$IMAGE_TAG"

Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

alexdo
Site Moderator
Site Moderator badge
January 4, 2023

Hello @2a463e4470634ef5b1c6eb8d929b8b

As per Bobby’s suggestion, this seems to be related to the Firewall configuration of your droplet.

If you’re running ufw or any other firewall management tool you can check that the port is open and accepting requests.

https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-with-ufw-on-ubuntu-22-04

Regards

Bobby Iliev
Site Moderator
Site Moderator badge
January 3, 2023

Hi there,

As you are getting connection refused when trying to visit that port, do you by any chance have a firewall on your Droplet?

If this is the case you need to open that port in order to be able to access it. For example if you are using ufw, then you need to run: ufw allow 4000.

Let me know how it goes!

Best,

Bobby

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel
Get started for free

Enter your email to get $200 in credit for your first 60 days with DigitalOcean.

New accounts only. By submitting your email you agree to our Privacy Policy.