The proper way of running two web services from one image?


What is the proper way of running two web services from one image?

I need to run two services from one image:
. flask
. boker server

flask gets data from bokeh server.

Can you give me the guide?

kind regards

Create two images, one with each server.

Create a Docker network (it doesn’t need any special configuration, you just need to create it)

docker create network mynet

Run the back-end server

docker run -d --net mynet --name boker boker

Run the front-end server, configuring it to point at the back-end server using the container’s name as a DNS name

docker run -d -p 8080:8080 --net mynet -e BOKER_SERVER_URL=http://boker:5006/ --name flask flask

You could wrap this up in a Docker Compose file to capture the very long container arguments.

There are a couple of practical reasons to do things this way:

… If one container needs to restart for whatever reason, you save the overhead of restarting the other container
… If you need to launch multiple copies of one service or another, you don’t have to start the other one; you can scale the two parts separately
… If you rebuild your front-end application, you’re not forced to restart your back-end application at the same time
… You’d need to install another tool into your container to be able to run multiple processes, learn how it works, and manage it, and that tool would largely duplicate core Docker functionality
… Smaller containers are generally easier to manage and distribute

(Also remember: you never need the private internal IP address of a Docker container; and it is extremely routine to delete containers, so if either of these containers keep persistent state, you’ll need to start them with a docker run -v option to store that data outside the container.)

1 Like

Than you,
It was very explanatory.