2

I have a very simple dockerfile based on the debian image, and I'm currently only installing the vim package. But somehow I can't execute the vim command inside the container. I have tried several base images (debian, ubuntu and alpine) but they all seem to have the same issue.

Does anybody have an idea about what I'm doing wrong?

Dockerfile:

FROM        debian:8.5
RUN apt-get update && apt-get install -y vim

docker-compose.yml:

version: '2'
services:
  web:
    container_name: frontend
    build: .
    ports:
      - '127.0.0.1:1337:80'

The result after building and executing the container:

$ docker-compose up -d && docker exec -it frontend bash
root@06ebc89b2706:/# vim
bash: vim: command not found
Wessel van der Linden
  • 2,592
  • 2
  • 21
  • 42
  • 3
    What is the output of the build process? What happens if you just `docker build` and `docker run` the image rather than using `docker-compose`? What is the output of the `docker-compose up` command without `-d`? – larsks Aug 11 '16 at 18:31
  • the build process: http://pastebin.com/RfQJ8GG7 . After running `docker run frontend vim` it works, vim opens. So there is probably something wrong with my docker-compose file – Wessel van der Linden Aug 11 '16 at 18:38
  • That's weird, I never had to put `tty: true` to my `docker-compose.yml` files before. And they always (almost) worked... Could you explain a bit why it worked in your case? I'm curious. Also, why not use `run` directly `docker-compose run web bash`? it don't see the point in created a detach container here. – Kruupös Aug 11 '16 at 20:03
  • @larsks I think without the `-d` the container is removed because there is no command running. you should add something like `sh -c "vim"` add the end of the docker-compose.yml in order to stay alive. – Kruupös Aug 11 '16 at 20:06
  • The container will be removed with or without `-d` if there is no process to run. `-d` does nothing magical; it just says, "run this in the background". – larsks Aug 11 '16 at 20:47

1 Answers1

1

Apparently I had to add tty: true to docker-compose.yml because I was executing with the -t option.

https://stackoverflow.com/a/32110513/1882337 has a nice explanation about the -t option.

Community
  • 1
  • 1
Wessel van der Linden
  • 2,592
  • 2
  • 21
  • 42