3

based on Moving docker-compose containersets

I have loaded the images :

$ docker images -a
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
br/irc              latest              3203cf074c6b        23 hours ago        377MB
openjdk             8u131-jdk-alpine    a2a00e606b82        5 days ago          101MB
nginx               1.13.3-alpine       ba60b24dbad5        4 months ago        15.5MB

but now i want to run them, as they would run with docker-compose, but i cannot find any example.

here is the docker-compose.yml

version: '3'
services:
  irc:
    build: irc
    hostname: irc
    image: br/irc:latest
    command: |
      -Djava.net.preferIPv4Stack=true
      -Djava.net.preferIPv4Addresses
      run-app
    volumes:
      - ./br/assets/br.properties:/opt/br/src/java/br.properties
  nginx:
    hostname: nginx
    image: nginx:1.13.3-alpine
    ports:
      - "80:80"
    links:
      - irc:irc
    volumes:
      - ./nginx/assets/default.conf:/etc/nginx/conf.d/default.conf

so how can i run the container, and attach to it, to see if its running, and in what order do i run these three images. Just started with docker, so not sure of the typical workflow ( build, run, attach etc )

so even though i do have docker-compose yml file, but since i have the build images from another host, can i possibly run docker commands to run and execute the images ? making sure that the local images are being referenced, and not the ones from docker registry.

Thanks @tgogos, this does give me a general overview, but specifically i was looking for:

$ docker run -dit openjdk:8u131-jdk-alpine
then:
$ docker ps -a
CONTAINER ID        IMAGE                      COMMAND                  CREATED             STATUS                      PORTS               NAMES
cc6ceb8a82f8        openjdk:8u131-jdk-alpine   "/bin/sh"                52 seconds ago      Up 51 seconds                                   vibrant_hodgkin

shows its running

2nd:

$ docker run -dit nginx:1.13.3-alpine
3437cf295f1c7f1c27bc27e46fd46f5649eda460fc839d2d6a2a1367f190cedc


$ docker ps -a
CONTAINER ID        IMAGE                      COMMAND                  CREATED             STATUS                      PORTS               NAMES
3437cf295f1c        nginx:1.13.3-alpine        "nginx -g 'daemon ..."   20 seconds ago      Up 19 seconds               80/tcp              vigilant_kare
cc6ceb8a82f8        openjdk:8u131-jdk-alpine   "/bin/sh"                2 minutes ago       Up 2 minutes                                    vibrant_hodgkin


then: finally:

[ec2-user@ip-10-193-206-13 DOCKERLOCAL]$ docker run -dit br/irc
9f72d331beb8dc8ccccee3ff56156202eb548d0fb70c5b5b28629ccee6332bb0

$ docker ps -a
CONTAINER ID        IMAGE                      COMMAND                  CREATED             STATUS                      PORTS               NAMES
9f72d331beb8        br/irc              "/opt/irc/grailsw"       8 seconds ago       Up 7 seconds                8080/tcp            cocky_fermi
3437cf295f1c        nginx:1.13.3-alpine        "nginx -g 'daemon ..."   56 seconds ago      Up 55 seconds               80/tcp              vigilant_kare
cc6ceb8a82f8        openjdk:8u131-jdk-alpine   "/bin/sh"                2 minutes ago       Up 2 minutes                                    vibrant_hodgkin

All three UP !!!!
kamal
  • 9,637
  • 30
  • 101
  • 168
  • I added some extra info to my answer about `docker-compose`. To say the truth, I am not quite sure what your question is, but I am here to help if you want. Actually, you ask about `docker-compose` which is a tool that does many things in the background (e.g. `docker-compose up` builds `images`, (re)creates / starts / attaches to `containers` and then you update your question saying that you were looking for simple docker commands like `docker run` and `docker ps`. – tgogos Nov 10 '17 at 09:45
  • 1
    @tgogos I truly appreciate your explanations, and they help. I am only reverting to docker commands, as I could not find equivalent in docker-compose. Thank you for your help. – kamal Nov 10 '17 at 21:24

2 Answers2

1

Your question is about docker-compose but you also ask things about run, build, attach which makes me think I should try to help you with some basic information (which wasn't so easy for me to cope with a couple of months ago :-)

images

Images are somehow the base from which containers are created. Docker pulls images from http://hub.docker.com and stores them in your host to be used every time you create a new container. Changes in the container do not affect the base image.

To pull images from docker hub, use docker pull .... To build your own images start reading about Dockerfiles. A simple Dockerfile (in an abstract way) would look like this:

FROM ubuntu                  # base image
ADD my_super_web_app_files   # adds files for your app
CMD run_my_app.sh            # starts serving requests

To create the above image to your host, you use docker build ... and this is a very good way to build your images, because you know the steps taken to be created.

If this procedure takes long, you might consider later to store the image in a docker registry like http://hub.docker.com, so that you can pull it from any other machine easily. I had to do this, when dealing with ffmpeg on a Raspberry Pi (the compilation took hours, I needed to pull the already created image, not build it from scratch again in every Raspberry).

containers

Containers are based on images, you can have many different containers from the same image on the same host. docker run [image] creates a new container based on that image and starts it. Many people here start thinking containers are like mini-VMs. They are not!

Consider a container as a process. Every container has a CMD and when started, executes it. If this command finishes, or fails, the container stops, exits. A good example for this is nginx: go check the official Dockerfile, the command is:

CMD ["nginx"]

If you want to see the logs from the CMD, you can docker attach ... to your container. You can also docker stop ... a running container or docker start ... an already stopped one. You can "get inside" to type commands by:

docker exec -it [container_name] /bin/bash

This opens a new tty for you to type commands, while the CMD continues to run.


To read more about the above topics (I've only scratched the surface) I suggest you also read:


docker-compose

After you feel comfortable with these, docker-compose will be your handy tool which will help you manipulate many containers with single line commands. For example:

docker compose up

Builds, (re)creates, starts, and attaches to containers for a service.

Unless they are already running, this command also starts any linked services.

The docker-compose up command aggregates the output of each container (essentially running docker-compose logs -f). When the command exits, all containers are stopped. Running docker-compose up -d starts the containers in the background and leaves them running

tgogos
  • 23,218
  • 20
  • 96
  • 128
  • 1
    @togogos now that i have all three container UP, how can i make sure the grails web application is running and on which port ? – kamal Nov 09 '17 at 18:45
  • `docker container ls -a` lists all the containers (even the stopped ones). You can check for container details with `docker inspect ...` – tgogos Nov 09 '17 at 18:54
0

To run your docker-compose file you would have to execute:

docker-compose up -d

Then to see if your containers are running you would have to run:

docker ps

This command will display all the running containers

Then you could run the exec command which will allow you to enter inside a running container:

docker-compose exec irc 

More about docker-compose up here: https://docs.docker.com/compose/reference/up/

Sergiu
  • 2,928
  • 3
  • 27
  • 37
  • How can i make sure that the local images are being used ? since docker-compose up does run, but on THIS host, it gives me compile issues, hence i build the docker images on another host, and copied them to this one. – kamal Nov 09 '17 at 17:16