-1

Created Docker container process is not showing using command docker ps --all

I have created only one Dockerfile in a directory, and which is a single available file inside the directory.

the Dockerfile contains following lines:

# Use an existing docker image as a base
FROM alpine

# Download and install a dependency
RUN apk add --update redis

# Tell the image what to do when it starts
# as a container
CMD ["redis-server"]

and after saving the file with name "Dockerfile" and without any extension, I am simply executing the command to build using docker build .

and the logs are as follows:

Sending build context to Docker daemon  2.048kB
Step 1/3 : FROM alpine
 ---> a24bb4013296
Step 2/3 : RUN apk add --update redis
 ---> Using cache
 ---> 218559ae3e9b
Step 3/3 : CMD ["redis-server"]
 ---> Using cache
 ---> fc607b62e266
Successfully built fc607b62e266
SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.

so, as above you can see the container image process is getting built successfully, but still the container not getting displayed using docker ps --all command.

Well I am using Windows 10 x64 OS & with assurance that no antivirus or firewall is blocker this docker. Am I missing something or making any mistake here?

ArifMustafa
  • 4,617
  • 5
  • 40
  • 48

1 Answers1

1

docker ps works like the unix command ps. It doesn't show all the docker images that could be run. It only shows the docker containers that are running (or with -a, have been run).

You've built a docker image but you haven't yet run it with docker run.

Try docker run --rm -it fc607b62e266 and if you have everything et up right, it should start up your redis server. (--rm removes the container when it stops running, generally a good practice unless you want it to persist).

You'll see your new image - not container because it hasn't been instantiated yet - in the output of docker images. Add a -t flag to give a tag to your docker build command and you'll see it under that name, otherwise, you can always use the image ref.

A container will only run while it's underlying "root process" is running. When running a service like redis-server, this means the container will run until signaled (docker service restart, system restrart, or docker kill).

While it is running, more processes can be executed within the container with docker exec. Each of these is a separate process, but all will be terminated when the "root process" ends. The converse, of course, is not true - ending the execed process doesn't affect the "root process".

erik258
  • 14,701
  • 2
  • 25
  • 31
  • earlier I were using the command `docker exec -it sh` and it were executing fine, but sudden it were not working, because the container were not available, could you tell this situation? – ArifMustafa Jul 24 '20 at 19:02
  • 1
    find it, `Successfully built fc607b62e266` is an image reference, not a container id, and using the command `docker run --rm -it fc607b62e266` the container process will start and so the container detail will get populated in `docker ps --all` containers status logs list. – ArifMustafa Jul 24 '20 at 19:12
  • I added some exec vs run info that can hopefully help you – erik258 Jul 24 '20 at 20:26