简体   繁体   中英

Create images from same Dockerfile

I have a nodejs application, which has two entry points worker.js and web.js

Basically, web should respond to all incoming http requests and worker should do some backend tasks.

Here is the question, how can I create two separate images from the same codebase? The problem is I can't create separate folder inside of my project with different Dockerfiles because I can't execute ADD ../ /app and I don't want to keep two copies of codebase. Project is in git repo but not published.

bash docker run -d -p 80:80 --name app-web application-web docker run -d --name app-worker application-worker

Thanks

Stick with one image per code-base, and use --workdir or just different CMD s to start the appropriate script:

docker run -d -p 80:80 --name app-web -w /app/web application
docker run -d --name app-worker -w /app/worker application

Abdullah's answer is the recommended one IMO (to save some disk space).

But to answer the default question, you can build an image with 2 different tags:

# assuming we're in the Dockerfile directory
docker build -t application-web .
docker build -t application-worker .

Then run different containers from these images:

docker run -d -p 80:80 --name app-web application-web
docker run -d --name app-worker application-worker

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM