Docker-compose push images built from node alpine and mysql

10/6/2020

Preliminary Info

I have a docker-compose file that describes two services, one built from a dockerhub mysql image and the other built from a dockerhub node alpine image. The docker-compose.yml is as follows:

version: "3.8"
services:
  client:
      image: node:alpine
      command: sh -c "cd server && yarn install && cd .. && yarn install && yarn start"
      ports:
        - "3000:3000"
      working_dir: /portal
      volumes: 
        - ./:/portal
      environment:
        MYSQL_HOST: mysql
        MYSQL_USER: root
        MYSQL_PASSWORD: password
        MYSQL_DB: files
  mysql:
      image: mysql:5.7
      volumes:
          - yaml-mysql-data:/var/lib/mysql
      environment:
        MYSQL_ROOT_PASSWORD: password
        MYSQL_DATABASE: files
    
volumes:
  yaml-mysql-data:

Current Understanding

I'm trying to deploy my app using kubernetes, but a kubernetes .yml file requires that I provide a path to my container images on dockerhub. However, I don't have them on dockerhub. I'm not sure how to push my images as they are built from the mysql and node images that I pull.

I know that docker-compose push can be used, however it's for locally built images; whereas I'm pulling images from dockerhub and am providing specific instructions in my docker-compose.yml when spinning them up.

Question

How can I push these images including the commands that should be run; e.g. command: sh -c "cd server && yarn install && cd .. && yarn install && yarn start"? (which is on line 5 of docker-compose.yml above)

Thanks

-- Parm
docker
docker-compose
kubernetes

1 Answer

10/6/2020

The logic that you put in the docker-compose.yml actually belongs with a Dockerfile. So create a Dockerfile for your nodejs applications (there are plenty of examples for this).

Then in your docker-compose.yml you build your own image that you can then push to a registry.

version: "3.8"
services:
  client:
      image: your_registry/your_name:some_tag
      build: .
      ports: ...
      environment: ....
-- Mihai
Source: StackOverflow