B
B
bengur22021-10-02 09:39:29
Nginx
bengur2, 2021-10-02 09:39:29

How to give a docker container from a server to a domain address?

The container has been successfully launched on the virtual machine.

dockerfile:

FROM node:latest

WORKDIR /usr/src/app

ARG NODE_ENVn
ENV NODE_ENV $NODE_ENV

COPY package*.json /usr/src/app/
RUN npm install

COPY . /usr/src/app

ENV PORT 5000
EXPOSE $PORT
CMD [ "npm", "start" ]


Launch:
sudo docker run -d -p 27073:5000 $CI_REGISTRY_IMAGE/$CI_COMMIT_BRANCH:latest


We check:
sudo docker container ls
CONTAINER ID   IMAGE                                           COMMAND                  CREATED       STATUS       PORTS
******************   registry.gitlab.com/*******:latest   "docker-entrypoint.s…"   9 hours ago   Up 9 hours   0.0.0.0:27073->5000/tcp, :::27073->5000/tcp

kYMhrRA.png

As I understand it, now there is a container on the virtual machine, which should be available outside of Docker on port 27073.

Did I do everything right?
How to give the container outside so that it is available on the mysite.com domain?

UPD 1:
Virtual Machine - Google Computed Engine.
There is a public IP.

UPD 2:
I directed the domain to the server IP, I get an error.
504 Gateway Time-out
The server didn't respond in time.

UUauR4s.png

UPD 3:
I specified port 27073 just so that each container has its own port.
Because I want to give different containers to different domains.
Maybe I'm doing something wrong :(

UPD 4:
curl http://localhost:27073
Returns my html

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Koryukov, 2021-10-02
@bengur2

The domain is bound not to the container, but to the ip address.
You did not specify exactly where this virtual machine was raised and for what purpose.
If you have a computer for personal use, then the easiest way is to use nip.io or register the domain and ip address of the virtual machine in the hosts file.
If you rented a virtual machine from some provider and want to make it available to everyone by domain, then you need to buy a domain and specify the ip address of the virtual machine in its settings.
Well, or use the same nip.io if this is a general service for a small circle of people.
UPD:
in order to open different web applications on different domains, you need an http proxy, which, based on the domain specified in the http request, will proxy this request to one or another internal address.
Usually, nginx is installed for this, which itself listens on ports 80 and 443.
All domains are configured so that they lead to the address of this server.
In the nginx config, they describe which application should respond to a specific domain, something like this:

server {
    listen 80;
    server_name site-1.domain.com;
    location / {
        proxy_pass http://127.0.0.1:27073;
    }
}
server {
    listen 80;
    server_name site-2.domain.com;
    location / {
        proxy_pass http://127.0.0.1:12345;
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question