How to create images ready to deploy with docker-compose

Viewed 543

How to create images ready to deploy with docker-compose ?

I am a bit confused with docker-compose, it feels as a great tool, however, how can I build an image for my service without having a Dockerfile?

What I would like to achieve is to create new image from the service declared inside docker-compose.yml file. For example, let's say I am having the following setup:

api:
  image: node:latest
  volumes:
    - "./api:/"
  ports:
    - "3001:3001"
  command: npm start

client:
  image: node:latest
  volumes:
    - "./client:/"
  ports:
    - "3000:3000"
  command: npm start

db:
  image: mysql:latest

So I am having 2 containers one how do I create ready to push docker image for each of this containers?

For example, I want to deploy api container

$ docker-compose build --no-cache api

Do I need to run next?

$ docker build -t api .

which requires Dockerfile, or can I go straight to image push?

And then push it with

docker push host_name/api:latest

1. What is the correct flow ?

2. Or maybe this is wrong way completely ?

Edit:

What I want to achieve here is to understand or get to know the correct flow for example of situation as I presented in my question where I would like to push this container to actual server. And ofc I do not want to run multicontainer app there. So given this example lets say I have one more container something like db (updated compose file example). After developing successful applications on my local machine using docker compose I want to deploy them lets say AWS where in most cases i have database service and what i need is to upload API container image to EC and I do not want to deploy db one or client to the same server.

So in order to do that i need to build docker image that i can push to my AWS. How to do that from what I have (docker compose setup) ?

1 Answers
Related