compose: docker-compose up seems to get the wrong image... ?
I am doing something pretty simple. I have a docker-compose.yml file:
  tsdb:
    build:
      context: ./tsdb_prod
    ....
and in the Dockerfile in that directory I have:
FROM influxdb:0.13
COPY file_prod /etc/file_prod
and I have the file_prod file in that directory.
running docker-compose build with --no-cache to rebuild my image after changes:
0s 👍  $> docker-compose build --no-cache
[snip]
Building tsdb
Step 1 : FROM influxdb:0.13
 ---> c7a58aa7ce3b
Step 2 : COPY file_prod /etc/file_prod
 ---> ff2aa86452fd
Removing intermediate container 91c3eafd328c
Successfully built ff2aa86452fd
2s 👍  $> docker run --rm -it ff2aa86452fd /bin/bash
root@0e660d6a1784:/# ls /etc/file_prod
/etc/file_prod
But when I do my docker-compose up I see
2s 👍  $> docker-compose up
Recreating task_tsdb_1
[snip]
tsdb_1   | run: open server: open service: open "/etc/file_prod": no such file or directory
I’m pretty new to Docker. I’m sure I’m missing something stupid here. Is it building one image but starting another? I do see
2s 👍  $> docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS               NAMES
f742363da3aa        58fcf34dd924        "/entrypoint.sh influ"   44 minutes ago      Exited (1) 34 minutes ago                       task_tsdb_1
[snip]
Not sure what’s going on with that. I would appreciate anyone’s insight.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 32
Weird thing is, if I run the app with
docker run, it’s fine. If I run it withdocker-compose up, it’s not. It’s almost as if docker-compose were picking the wrong image to spin the container from - an intermediary image, maybe?I had this issue. For anybody getting a similar thing, I realised I was accidentally binding the local folder (using docker-compose) as a volume into the docker container like this:
Which I must have done early-on, trying to get live-reload working or something. This was confusing the heck out of docker-compose and was showing a “container” version of the filesystem when putting
RUN ls -alstatements inDockerfileand a “host” version of the filesystem when usingCMD ls -alresulting in completely different outputs. Check to make sure you aren’t doing something similar.Leaving a comment here in case it helps someone else.
docker-compose stopfollowed bydocker-compose buildanddocker-compose startisn’t good enough, you have todocker-compose down,docker-compose buildanddocker-compose upbecause down/up is when docker actually maps images to containers. If you don’t use down/up docker-compose will use the old pre-existing containers.This is probably obvious to seasoned docker users, but a casual like me didn’t understand this nuance and it very well could be the trap many of the commenters on this thread are accidentally falling into.
@aanand awesome, it worked! Summary of changes:
New line in
.env:Removal of
imageandcontainer_namefromdocker-compose.ymlImages and containers no longer conflict and I see
developmentsite_web_1andproductionsite_web_1indocker ps. Awesome!@kachkaev This isn’t a bug, and has nothing to do with caching.
Both your directories are named the same thing (
docker), so when you rundocker-compose upin either directory you’re working on the same project. Each time you’re updating the configuration of the same service (web) to change both the image name and container name.It looks like what you actually want is two separate apps, each with its own image and container. In that case, I suggest doing the following:
--project-nameoption orCOMPOSE_PROJECT_NAMEenvironment variable to set a different project name for each app. For example,myappdevandmyappprod.container_nameoption from both Compose files - it’s unnecessary.If you run
docker-compose upin both directories, you should now have two containers:myappdev_webandmyappprod_web.I’m having the same problem here.
Further, if I
docker run image, the file is there. If Idocker-compose up, the file is not there.Exact same behavior on the latest beta on OSX and on Windows.
Can you try running
docker-compose down -v --rmithen runbuild/upagain?