I have a web service that is packed inside Docker image. I use compose to build this image and run it. I use docker desktop to run docker containers.
So, to run service I just need to type:
docker-compose run app
compose file:
version: "3.6"
services:
app:
build:
context: .
target: app
ports
- 5001:5001
docker file:
FROM python:3.10-slim as app
RUN mkdir -p /app
WORKDIR /app
COPY entrypoint.sh .
CMD ["sh", "/app/entrypoint.sh"]
However, I face following issue: when I try to get this service GET http://localhost:5001/up I get Error: connect ECONNREFUSED
I can't figure out why I can't access service. Any help/comment/explanation will be mush appreciated.
Did you check if the docker is running using the command docker ps ?
If it's running, please check if the port is listening using netstat -tnulp | grep 5001
Also check if firewall is blocking the connection
Related
The problem is that docker compose cannot build image, failing on RUN npm ci. But after hours of debugging, I isolated the problem and pinned it in this minimal setup:
My docker-compose.yml
version: '3.8'
services:
myapp:
build:
dockerfile: Dockerfile
context: .
target: development
command: sleep Infinity
My Dockerfile
FROM node:18-alpine AS development
RUN ping google.com
When I run docker compose -f docker-compose.yml up -d --build
I'm getting error:
What I tried so far
In Dockerfile replace ping google.com to ping <real-ip>. ✅ And it works, so I assume it's DNS problem.
Add dns into docker-compose.yml: dns: 8.8.8.8. ❌ No luck
Run under super user sudo docker compose …. ❌ No luck
I tried to build image from Dockerfile without compose, using just docker build command. ✅ And it works, so the problem with docker compose.
Commented RUN ping … command, so it does not fail and runs sleep Infinity form the compose config. Then I connected into the container via docker exec -it <container> sh and was able to ping google and run npm ci. So when container is running it has access to DNS. The problem happens only in docker compose on the build stage from Dockerfile.
Environment
It's a VPS on hetzner. I ssh under a user with sudo and docker group.
I'm trying to containerize my vue application created from vue-cli. I have a docker-compose.yml looking like this:
version: '3.8'
services:
npm:
image: node:current-alpine
ports:
- '8080:8080'
stdin_open: true
tty: true
working_dir: /app
entrypoint: [ 'npm' ]
volumes:
- ./app:/app
I have in the same directory the docker-compose.yml and the /app where the vue source code is located.
/vue-project
/app (vue code)
/docker-compose.yml
I install my node dependencies:
docker-compose run --rm npm install
They install correctly in the container as I see the folder appear in my host.
I am running this command to start the server:
docker-compose run --rm npm run serve
The server starts to run correctly:
App running at:
- Local: http://localhost:8080/
It seems you are running Vue CLI inside a container.
Access the dev server via http://localhost:<your container's external mapped port>/
Note that the development build is not optimized.
To create a production build, run npm run build.
But I cannot access it at http://localhost:8080/ from my browser. I've tried different ports, I've also tried to run the command like this:
docker-compose run --rm npm run serve --service-ports
But none of this works. I've looked at other dockerfiles but they are so different from mine, what am I exactly doing wrong here?
docker ps -a
is showing these:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cf0d5bc724b7 node:current-alpine "npm run serve --ser…" 21 minutes ago Up 21 minutes docker-compose-vue_npm_run_fd94b7dd5be3
ff7ac833536d node:current-alpine "npm" 22 minutes ago Exited (1) 22 minutes ago docker-compose-vue-npm-1
Your compose-file instructs docker to expose the container's port 8080 to the host's port 8080, yet your docker ps output shows the container is not listening.
Is it possible your containerized app is not listening on 8080?
I'm having a couple of issues running docker-compose.
docker-compose up already works in starting the webservice (stuffapi) and I can hit the endpoint with http://localhost:8080/stuff.
I have a small go app that I would like to run with docker-compose using a local dockerfile. The dockerfile when built locally cannot call the stuffapi service on localhost. I have tried using the service name, ie http://stuffapi:8080 however this gives an error lookup stuffapi on 192.168.65.1:53: no such host.
I'm guessing this has something to do with the default network setup?
After the stuffapi service has started I would like my service to be built (stuffsdk in dockerfile), then execute a command to run the go app which calls the stuff (web) service. docker-compose tries to build the local dockerfile first but when it runs its last command RUN ./main, it fails as the stuffapi hasn't been started first. In my service I have a depends_on the stuffapi service so I thought that would start first?
docker-compose.yaml
version: '3'
services:
stuffapi:
image: XXX
ports:
- 8080:8080
stuffsdk:
depends_on:
- stuffapi
build: .
dockerfile:
From golang:1.15
RUN mkdir /stuffsdk
RUN mkdir /main
ADD ./stuffsdk /stuffsdk
ADD ./main /main
ENV BASE_URL=http://stuffapi:8080
WORKDIR /main
RUN go build
RUN ./main
Am starting with Docker and running into an issue. I want to enabled mod_rewrite in an apache-container and am using this docker-compose.yml
version: '3'
services:
php-apache:
image: php:7.2.1-apache
ports:
- 80:80
volumes:
- ./DocumentRoot:/var/www/html:z
and this Dockerfile:
FROM php:7.2.1-apache
RUN a2enmod rewrite
RUN service apache2 restart
I run "docker build --no-cache ." with output:
Sending build context to Docker daemon 90.16MB
Step 1/3 : FROM php:7.2.1-apache
---> f99d319c7004
Step 2/3 : RUN a2enmod rewrite
---> Running in 883573f39a39
Enabling module rewrite.
To activate the new configuration, you need to run:
service apache2 restart
Removing intermediate container 883573f39a39
---> 18c40ce865a6
Step 3/3 : RUN service apache2 restart
---> Running in b79bab530dc7
Restarting Apache httpd web server: apache2AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
.
Removing intermediate container b79bab530dc7
---> 8e2cfa7094f7
Successfully built 8e2cfa7094f7
Result: mod_rewrite not installed. When I log in to the console and manually run "a2enmod rewrite" all works fine. What am I missing here?
The docker build --no-cache . creates the docker image <none>:<none>.
Your compose-file references the base image: php:7.2.1-apache. You're basically preparing an image that you're not using.
You might want to use the -t argument in order to tag the image that you are building and then reference that image in the compose file. E.g:
docker build -t my-awesome-php-with-a2enmod --no-cache .
version: '3'
services:
php-apache:
image: my-awesome-php-with-a2enmod
ports:
- 80:80
volumes:
- ./DocumentRoot:/var/www/html:z
I am working on setting up two Docker containers using Docker for Windows. A simple node based web app, and a dotnet core API application. I am starting both these containers using "docker-compose up". The node app starts up perfectly and I can hit the exposed URL, however the dotnet app isn't seeming to work.
The output of the docker-compose up command is below:
application.client_1 | INFO: Accepting connections at http://localhost:8080
application.api_1 | warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
application.api_1 | No XML encryptor configured. Key {cc83a8ac-e1de-4eb3-95ab-8c69a5961bf9} may be persisted to storage in unencrypted form.
application.api_1 | Hosting environment: Development
application.api_1 | Content root path: /app/application.Api
application.api_1 | Now listening on: http://[::]:80
application.api_1 | Application started. Press Ctrl+C to shut down.
The Docker file looks like the following:
FROM microsoft/dotnet AS build
WORKDIR /app
ENV PORT=8081
COPY application.Api/application.Api.csproj application.Api/
COPY application.Business/application.Business.csproj application.Business/
COPY application.DataAccess/application.DataAccess.csproj application.DataAccess/
COPY application.DataModel/application.DataModel.csproj application.DataModel/
WORKDIR /app/application.Api
RUN dotnet restore
WORKDIR /app/
COPY application.Api/. ./application.Api/
COPY application.Business/. ./application.Business/
COPY application.DataAccess/. ./application.DataAccess/
COPY application.DataModel/. ./application.DataModel/
WORKDIR /app/application.Api
RUN dotnet publish -c Release -o out
FROM microsoft/dotnet AS runtime
WORKDIR /app/application.Api
COPY --from=build /app/application.Api/out .
ENTRYPOINT ["dotnet", "application.Api.dll" ]
EXPOSE $PORT
I am unable to get an IP and thus hit the API url. Any thoughts would be much appreciated as I am pretty new to Docker.
UPDATE 1: Compose YML
version: '3.4'
services:
tonquin.api:
image: application.api
ports:
- 8081:5000
build:
context: .
dockerfile: Dockerfile
tonquin.client:
image: application.client
ports:
- 8080:8080
build:
context: .
dockerfile: ../application.Client/Dockerfile
As they've mentioned it seems your container is running on port 80. So for whatever reason that's the port being exposed.
Maybe the EXPOSE $PORT is not returning 8081 as you expect?
When you run the container, unless you specify where to map it, it will only be available at the container's IP at the exposed port (80 in your case). Find out this container Ip easily by running docker inspect <container_id>
Test your image by doing something like docker run -p 8080:80 yourimage. You'll see that in addition to the port 80 that the image exposes, it is being mapped to your local port 8080 so that http://localhost:8080 should be reachable.
See this in case it helps you
See this answer.
The base dotnet image overrides the default kestrel port. Why, I don't know. Adding the environment declaration to my docker file fixed the problem for me.
It's trying to use the IPv6 protocol on the network interface. Disable IPv6 and restart docker. It also looks like you might have both apps trying to use port 80. You can only serve one item on a given port with a given interface/IP. Try setting the API to use a different port number, like 8080.