I deployed Spring Boot application using Jenkins by docker-compose.yml. I can access the created container, but I cannot access the container from another machine on the same.network.
The command I used:
docker-compose run -d app
docker-compose.yml
version: '3.1'
services:
app:
container_name: xxxxxx
image: xxxxxx
build: ./
ports:
- "8000:8000"
restart: always
environment:
- POSTGRES_DB_HOST="xxxxxxxxx"
- POSTGRES_PASSWORD="xxxxx"
- POSTGRES_USER="postgres"
- POSTGRES_DB="db_name"
How to solve the problem? Thanks in advance.
EDIT:
After Jenkins deployed the application successfully, I used docker inspect
to check the container's IP and then I accessed on the host machine(Let's say the container has IP 1.2.3.4) with the following URL:
http://1.2.3.4:8000
I try to access another machine in the.network with the host machine by accessing URL like following(Let's say host machine has IP 2.3.4.5):
http://2.3.4.5:8000
But I could not see deployed web page like on the host machine, the error was like below:
This site can’t be reached
x.x.x.x refused to connect.
Your problem is the use of the docker-compose run
command. From the documentation :
The second difference is that the docker-compose run command does not create any of the ports specified in the service configuration. This prevents port collisions with already-open ports.
Because you're using run
, the port mapping between the host port 8000 and the container port 8000 isn't configured.
The normal way you bring up a docker-compose stack is through the use of the up
command:
docker-compose up -d
You can specify a single service if you're trying to avoid bringing up all the services in your docker-compose.yaml
file:
docker-compose up -d app
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.