1

I am just a beginner in docker. I am building my own docker file using this code.

FROM alpine
RUN apk add --update redis
CMD ["redis-server"]

but the third command CMD is not running. I am unable to see successfully built message.

This is the cmd output that I am getting:

this is the cmd  output that I am getting.

Please help.

3
  • Have you considered running one of the official Redis images? hub.docker.com/_/redis Commented Dec 1, 2020 at 15:32
  • yes official redis-server is running but that docker stopfile stops execution at CMD command and unable to get Successfully built message Commented Dec 1, 2020 at 16:35
  • The image was built sucessfully? Commented Dec 2, 2020 at 12:56

4 Answers 4

4

CMD is command that runs when you create a container.

you need to run a container from that image after the build

docker run -it -p 6379:6379 [image_name] or [image_id]

6379 is default port for redis

Sign up to request clarification or add additional context in comments.

5 Comments

but image is not created. I am unable to see the image_id anywhere
what do you get on "docker images" ?
I didn't get that image in "docker images" command
your imageid should be ddf3487d3032. you can build and tag : docker build -t xxx .
I have run into the same issue as the questionnaire. I've posted by question not knowing this was already asked here: superuser.com/questions/1712303/… - Maybe it has to do something with running the Docker in Windows as opposed to running it in Mac or Linux.
0

You should run the last obtained image. Don't expect that Dockerfile will do this for you.

Let me explain:

First let's begin by recalling what is an image.

Image = File System Snapshot + Startup Command.

The full story recaped here :

You have got 3 instructions in your Dockerfile (FROM, RUN, CMD).

When you "docker build .", here is what happens:

$ docker build .

[+] Building 1.8s (6/6) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                                                                   0.0s
 => => transferring dockerfile: 37B                                                                                                                                                                    0.0s
 => [internal] load .dockerignore                                                                                                                                                                      0.0s
 => => transferring context: 2B                                                                                                                                                                        0.0s
 => [internal] load metadata for docker.io/library/alpine:latest                                                                                                                                       1.7s
 => [1/2] FROM docker.io/library/alpine@sha256:ec14c7992a97fc11425907e908340c6c3d6ff602f5f13d899e6b7027c9b4133a                                                                                        0.0s

FROM instruction: Here is the generation of the alpine image with a file system. The image id is displayed after the "sha256:". Let's call it image A.

 => CACHED [2/2] RUN apk add --update redis                                                                                                                                                            0.0s
 => exporting to image                                                                                                                                                                                 0.0s
 => => exporting layers                                                                                                                                                                                0.0s
 => => writing image sha256:45e4f46a107d5b213a2b325204322e52ac4e4eeeb2282ba66e5c6455310ad282

RUN instruction: It takes the image generated during the previous step (image A). It creates a container out of it, it executes the command in this container. The file system should be modified right now (redis added thanks to the package manager apk). A snapshot is taken from the file system of this container and saved as output for the next instruction (next one is CMD). This output is an image with the id shown after the second "sha256:". Let's call it image B.

Now the image B is the one that contains: a file system snapshot (with redis inside) + a startup command (redis-server).

This image (B) is now ready to be run. The result would be a container:

 $ docker build run image_B
1:C 07 Apr 2021 09:40:13.168 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 07 Apr 2021 09:40:13.168 # Redis version=6.0.11, bits=64, commit=1522534f, modified=0, pid=1, just started
1:C 07 Apr 2021 09:40:13.168 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
1:M 07 Apr 2021 09:40:13.170 * Running mode=standalone, port=6379.
1:M 07 Apr 2021 09:40:13.170 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1:M 07 Apr 2021 09:40:13.170 # Server initialized
1:M 07 Apr 2021 09:40:13.171 * Ready to accept connections

Comments

0

Latest binary release does not run the CMD command on executing docker build. You will have to execute the docker run command.

Comments

-1

Curious, I get good result,
are you up to date ? (I run on 19.03.13).
If it do not work maybe try to reinstall.
Bash output

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.