1

I have three .sh files that I run in order to build and run docker images. As of yesterday, I can't seem to create any new ones that will work. It's weird because even if I copy the working ones exactly it still doesn't work.

I can run the lines inside the shell script in a terminal and they will work. I don't know how or why this is not working.

Edit: I can run the files, but they spit out something like

Error response from daemon: No such container: foo-container

which is not true since I can see the container with docker ps

Example:

This is an old script that works

#! /bin/bash
docker stop cb-server
docker rm cb-server
docker rmi couchbase.server.container
docker build -t couchbase.server.container .

But if I make a new one with the exact same code, and run it, I get this:

Error response from daemon: No such container: cb-server
Error response from daemon: No such container: cb-server
Error response from daemon: invalid reference format
Cilvet
  • 470
  • 6
  • 10
  • Can you share any of the scripts? – Jay Dorsey Oct 19 '17 at 15:38
  • There you go, I'm going a bit crazy about this right now – Cilvet Oct 19 '17 at 16:06
  • You will get the no such container error when the container is already stopped and removed. Run `docker ps -a | grep cb-server` and `docker images | grep couchbase` and see if either return a response – Jay Dorsey Oct 19 '17 at 16:12
  • As I said, docker ps and all of those commands (I just tried them just in case) show the images and containers that I have created. I have no trouble with that, it's just the new scripts that I create that are not able to access those images and containers for some reason (when the old ones clearly can find them and access them) – Cilvet Oct 20 '17 at 07:25

2 Answers2

1

I had exactly this problem when I was editing scripts on my server machine (running Ubuntu) from my PC (running windows). What fixed it was checking the end of line formatting. Editing .sh scripts on Windows leads to DOS line endings. Apparently docker cannot handle those (and can't even tell what the problem is).

ouflak
  • 2,458
  • 10
  • 44
  • 49
Viper
  • 11
  • 2
0

The two "no such container" responses are likely caused because the container and images doesn't exist on your machine (e.g. you already stopped and removed them)

You may be able to wrap these commands with a conditional before attempting to run them.

https://stackoverflow.com/a/38576401/2892779

The invalid reference format may be this:

https://github.com/moby/moby/issues/25599

Only lower case characters are permitted for images names (I don't se anything in your posted script with that problem, but you said you had 3 so assuming possibly one of the others)

Jay Dorsey
  • 3,563
  • 2
  • 18
  • 24
  • 1
    Thank you for your answer. the container and images not existing on my machine was the first thing I thought of, but they do exist, docker shows them clearly with docker ps and they can be found by the other (older) scripts. I am afraid this might have something to do with permissions – Cilvet Oct 20 '17 at 07:19
  • Are you running sudo for any commands? What OS and version of docker on your host? Have you tried restarting the docker daemon? Are the scripts on the same machines? Same folders? What if you rename the old script? Can you run `last -al` in the folder where both scripts exist so permissions can be inspected? Have you run `chmod +x` on the script? Also I just noticed this but your bash script should remove the space between the # and the ! – Jay Dorsey Oct 20 '17 at 12:27
  • Scratch the comment about the shebang line. I was browsing on my phone earlier this morning and must have read it incorrectly. – Jay Dorsey Oct 20 '17 at 14:39