Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run docker image with docker-compose

I have my simple app in C# that connect with postgreSQL. I would like to create image with this app and just run with docker.

Everything is ok when I use:

$ docker build
$ docker run postgres
$ docker run my_app

Additionally, there is everything ok, when I use compose from application directory:

$ docker-compose build
$ docker-compose up

But is there any chance for use docker-compose for image that I built previous?

I would like to publish this image to my repo and somebody else from my team just download and run this image (app + database).

When I do compose-build and next compose run my_app I have exception during connecting to database:

dbug: Npgsql.NpgsqlConnection[3]
      Opening connection to database 'POSTGRES_USER' on server 'tcp://postgres:5432'.

Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.AggregateException: One or more errors occurred. (No such device or address) ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException: No such device or address

My current docker-compose.yml file:

version: '2'

services:

  web:
    container_name: 'postgrescoreapp'
    image: 'postgrescoreapp'
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - .:/var/www/postgrescoreapp
    ports:
     - "5001:5001"
    depends_on:
     - "postgres"
    networks:
      - postgrescoreapp-network

  postgres:
    container_name: 'postgres'
    image: postgres
    environment:
      POSTGRES_PASSWORD: password
    networks:
      - postgrescoreapp-network

networks:
  postgrescoreapp-network:
    driver: bridge
like image 947
GrzesiekO Avatar asked Jan 05 '17 09:01

GrzesiekO


People also ask

How do I run Dockerfile from Docker compose?

If you already have some Dockerfiles, add Docker Compose files by opening the Command Palette. Use the Docker: Docker Compose Files to the Workspace command, and, when promoted, choose the Dockerfiles you want to include. You can also add Docker Compose files to your workspace when you add a Dockerfile.

Does Docker compose pull images?

Pulls an image associated with a service defined in a docker-compose. yml or docker-stack. yml file, but does not start containers based on those images.

Does Docker compose run rebuild image?

docker-compose run is supposed to run a container. If the container requires to build an image, the run command also builds the container but it doesn't have to rebuild the image. docker run does not build either. docker-compose up does everything so you have the option to rebuild.


1 Answers

you should build the image with this name: (registryName:RegistryPort)/imagename:version

$ docker build -t myRegistry.example.com:5000/myApp:latest .
$ docker build -t myRegistry.example.com:5000/myDb:latest .

Now add these lines to the docker-compose file :

Myapp:                                                    
  image: myRegistry.example.com:5000/myApp:latest 

MyDb:                        
  image: myRegistry.example.com:5000/myDb:latest

And then push it :

$ docker push myRegistry.example.com:5000/myApp:latest
$ docker push myRegistry.example.com:5000/myDb:latest

Your mate should now be able to pull it now

$ docker pull myRegistry.example.com:5000/myApp:latest
$ docker pull myRegistry.example.com:5000/myDb:latest
like image 75
wilsonW Avatar answered Oct 03 '22 12:10

wilsonW