0
votes

I'm trying to create docker image by docker-compose. How I can do that?

I can start my project (spring boot + cassandra) by docker-compose up. And everything works great. But in next step I want to make from this project image, push to docker hub and pull it from docker hub to test on other computer. Im tried 'docker-compose build', 'docker-compose push' and then 'docker-compose pull'. After pull I can see information that cassandra and spring-boot-app is downloaded. But then, when I want to run this image by 'docker run' but it runs only springboot, without cassandra.

This is my docker-compose.yaml file:

version: '3'

services:
  cassandra:
    build:
      context: ../
      dockerfile: docker/cassandra/Dockerfile
    ports:
      - "9042:9042"
    container_name: cassandra

  spring-boot-cassandra:
    build:
      context: ../
      dockerfile: docker/springbootsample/Dockerfile
    links:
      - cassandra
    ports:
     - "8080:8080"
    environment:
      SPRING_DATA_CASSANDRA_CONTACT_POINTS: cassandra
    container_name: springboot
    entrypoint: /wait-for-it.sh cassandra:9042 -- java -Djava.security.egd=file:/dev/./urandom -jar app.jar
    depends_on:
      - "cassandra"
    image: myrepo/springbootsample


networks:
  default:
    driver: bridge
1

1 Answers

0
votes

docker-compose is used to handle multiple images. I guess you are thinking it will merge two images into one, which will not happen.

docker run is used to run only one image at a time, this was the limitation because of that docker-compose was introduced.

docker-compose up does docker run, docker network create/add etc. commands to create you an environment. For use,

docker-compose build will build all your images present in the docker-compose.yml file.

docker-compose push will push all your images to the hub.

docker-compose pull will download those images from the hub if present.

and finally, if you want to run those images, use docker-compose up. If the images are not present it will download those images first from the hub.