I have a server listening on port 6000 inside a docker container and I've exposed port 6000 in the dockerfile:
FROM rust:latest
WORKDIR /usr/src/server
COPY . .
RUN cargo install --path .
EXPOSE 6000
RUN cargo run
then run it using:
docker build -t server
docker run --rm -it -p 6000:6000 server
I then have a client in another container trying to make a tcp connection at port 6000, but it's failing to connect. When they're both run not in containers they can connect no issues, but trying to use docker is causing issues. Do I have to do something with my clients container in order to connect to port 6000 outside of its own container? I think it's probably a very simple issue I'm just new to docker so any help would be greatly appreciated.
CodePudding user response:
The RUN
command is a build time execution, I think you are looking for CMD instead. Also the EXPOSE is not necessary, it only serves documentational purposes. Lastly, you need to check whether the container is even running before trying to access it from the client. Do a docker ps -a
after starting the server and look at the container status. If it isn't running you can check the logs with docker logs <container name / hash>
. Let me know if you have questions.