-1

I Build an dockerfile for centos7 and a docker-compose file for linking volumes to the container and set some local variables. When i start the container with

docker-compose up --build

My dockerfile does its work. After starting the container it exits with Exitcode 0.

I want to acess my container by shell. How can i do that without terminating the container and staying open?

My Dockerfile:

FROM centos:7
RUN yum -y update
CMD /bin/sh 

My Composer file:

version: '2'
services:
 media:
  build: .
  volumes:
   - ./media:/media
   - ./media/bin/x86_64/release/:/usr/local/lib/
  command: bash
  environment:
   - LD_LIBRARY_PATH=usr/lib64:/usr/local/lib
  expose:
   - "8080"
   - "80"
   - "443"

Any ideas?

To keep it open in a normal docker usage is explained already, but not in context to the usage with docker-compose.

Marcel Wolf
  • 326
  • 3
  • 20
  • Possible duplicate of [Docker container will automatically stop after "docker run -d"](http://stackoverflow.com/questions/30209776/docker-container-will-automatically-stop-after-docker-run-d) – nwinkler Jan 04 '17 at 10:24
  • it is not a duplicate because of the usage of Docker-compose in this context . Run as a normal docker container works a expected, but how to keep it open in a docker-compose context it isn't explained. – Marcel Wolf Jan 04 '17 at 11:43
  • Does it stay up if you run it with `docker run -d`? That's what Docker Compose does. It should terminate once the yum update has completed... – nwinkler Jan 04 '17 at 11:46

2 Answers2

2

Use docker-compose run instead of docker-compose up.

$ docker-compose run --rm media /bin/bash
[root@54eb39f672c7 /]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)

docker-compose up is used to start a service which is always running.

On the other hand, docker-compose run is used to run a one-off command.

docker-compose run does not have the option of --build. If you want to change the Dockerfile and the rebuild the image, use docker-compose build.

minamijoyo
  • 3,305
  • 1
  • 18
  • 20
  • thank you, this would work if windows is not docker host, it doesnt support interactive mode for docker-compose yet – Marcel Wolf Jan 05 '17 at 09:56
0

Add -d to run in detach mode

docker-compose up -d --build
gile
  • 5,580
  • 1
  • 25
  • 31