The portainer container is created with " 9000:9000 9000:9000" as published ports but the jenkins_api container is not created with 8081 port.
Can this be due to problem with jar or something is wrong with my docker config ?
When you say that the jenkins_api container is not created with 8081 port, do you mean it shows up in docker ps but without the port exposed? Or do you mean when you try to reach the port it doesn’t work in some fashion? Can you be more specific?
Can you post any logs that happen after docker-compose up -d? Can you also post docker ps -a and docker logs jenkins_api?
and it resulted in everything working from what I could tell
⛵ docker-desktop in ~ on ☁️ default
❯ docker-compose up -d
Creating alexhokanson_portainer_1 ... done
Creating jenkins_api ... done
⛵ docker-desktop in ~ on ☁️ default
❯ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d921bd4365b3 alpine "sleep 99999" 6 seconds ago Up 2 seconds 0.0.0.0:8081->8081/tcp, :::8081->8081/tcp jenkins_api
ce27fc8afbef portainer/portainer "/portainer -H unix:…" 6 seconds ago Up 3 seconds 0.0.0.0:9000->9000/tcp, :::9000->9000/tcp alexhokanson_portainer_1
⛵ docker-desktop in ~ on ☁️ default
❯ # both containers are running and both have the expected exposed ports
⛵ docker-desktop in ~ on ☁️ default
❯ docker logs jenkins_api
⛵ docker-desktop in ~ on ☁️ default
❯ # I didn't expect logs since we're only doing a sleep command
It looks like the port is not being exposed because the container is stuck in a “boot loop”. e.g. it is always restarting, so it never becomes healthy and allows Docker to expose a port on it.
I have an example here. I created a container like this: docker run --entrypoint=bash --restart=always -p 8080:8080 -d ubuntu -c 'sleep 5 && exit 1'
Then I kept checking docker ps and here is the output over the next 5 seconds (the sleep time)
❯ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ee268f3441ef ubuntu "bash -c 'sleep 5 &&…" 4 seconds ago Up 2 seconds 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp nifty_ellis
❯ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ee268f3441ef ubuntu "bash -c 'sleep 5 &&…" 5 seconds ago Up 3 seconds 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp nifty_ellis
❯ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ee268f3441ef ubuntu "bash -c 'sleep 5 &&…" 6 seconds ago Up 4 seconds 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp nifty_ellis
❯ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ee268f3441ef ubuntu "bash -c 'sleep 5 &&…" 7 seconds ago Up 5 seconds 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp nifty_ellis
❯ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ee268f3441ef ubuntu "bash -c 'sleep 5 &&…" 8 seconds ago Restarting (1) 1 second ago nifty_ellis
❯ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ee268f3441ef ubuntu "bash -c 'sleep 5 &&…" 9 seconds ago Restarting (1) 2 seconds ago nifty_ellis
❯ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ee268f3441ef ubuntu "bash -c 'sleep 5 &&…" 10 seconds ago Up Less than a second 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp nifty_ellis
Notice how upon restart it doesn’t show the ports and then they come back after the pod has been up for a bit. I recommend fixing the restart issue and then seeing if the ports stay bound to the container.
yes it got stuck on boot loop and it was caused by the jar file running command.I think the problem is with the location of the jar being in the same level of the dockerfile and docker-compose i changed it to be :
FROM anapsix/alpine-java
USER root
RUN mkdir -p /var/run/jars/
COPY jenkins_api.jar /var/run/jars/
EXPOSE 8081
ENTRYPOINT [ "java" ]
CMD ["-?"]