I have created a container using the following command: docker container run -i ubuntu
. However, when I try to run a command within the container, such as cd
, I get the following error: bash: line 1: cd: $'bin\r': No such file or directory
. What could be the issue?

- 77
- 6
-
2Does this answer your question? [Confused about Docker -t option to Allocate a pseudo-TTY](https://stackoverflow.com/questions/30137135/confused-about-docker-t-option-to-allocate-a-pseudo-tty) – Noam Yizraeli Oct 27 '21 at 08:45
-
1@NoamYizraeli Actually I have been trying to run the container without using the -t option to understand what this option does , so you exactly gave me what I need, many thanks man. – muhsen97 Oct 27 '21 at 08:50
-
1That `\r` is the universal sign of DOS line endings in a Linux container, though I'd be surprised to see an unmodified `ubuntu` image produce that. Did you at some point `docker build -t ubuntu ...` something, or have a Compose setup with both a `build:` block and `image: ubuntu`? Does `docker rmi ubuntu` help? (Why are you running `ubuntu` unmodified?) – David Maze Oct 27 '21 at 10:19
-
@DavidMaze, yes I have used `docker build -t ubuntu ...` as I was trying to understand what the `-t` option actually does. Is that the reason of having this error? – muhsen97 Oct 27 '21 at 19:09
1 Answers
When you docker run
an image, or use an image in a Dockerfile FROM
line, or name an image:
in a Docker Compose setup, Docker first checks to see if you have that image locally. If you have that image, Docker just uses it without checking Docker Hub or the other upstream registry.
Meanwhile, you can docker build
or docker tag
an image with any name you want...even a name that matches an official Docker Hub image.
You mention in a comment that you at some point did run docker build -t ubuntu ...
. That replaces the ubuntu
image with what you built, so when you later docker run ubuntu
, it's running your modified image and not the official Docker Hub Ubuntu image.
This is straightforward to fix. If you
docker rmi ubuntu
it will delete your local (modified) copy, and the next time you use it, Docker will automatically pull it from Docker Hub. It should also work to
# Explicitly get the Docker Hub copy of the image
docker pull ubuntu
# Build a custom image, pulling whatever's in the FROM line
docker build --pull -t my/image .
(You can also hit this in a Docker Compose setup if you specify both image:
and build:
; this instructs Compose on an explicit name to use for the built image. You do not need to repeat the FROM
line in image:
, and it causes trouble if you do. The resolution is the same as described above. I might leave image:
out entirely unless you're planning to push the image to a registry.)

- 130,717
- 29
- 175
- 215