Some container images include more than one executable file, and you may want to run a container using other than the default command and/or pass some arguments to it. In this challenge, you'll practice running an alternative executable in an off-the-shelf container image.
When invoked without extra arguments, the docker run redis command will start a redis-server binary in a container.
However, the redis image also includes the redis-cli executable,
which can be used to interact with any Redis server instance
(not necessarily the one running in the same container).
This makes a redis container a handy way to run redis-cli without installing it on your machine.
But only if you know how to override its default command 😉
To get started, run redis-cli with the --version flag in a redis container:
Hint 1 💡
Docker designed containers in such a way that they can be run without any additional arguments by default.
For instance, docker run redis will start a redis process in a container,
because the redis image has a default redis-server command
defined in its Dockerfile:
FROM ...some base image...
RUN ..install redis...
# Run the redis-server command by default
CMD ["redis-server"]
However, oftentimes container images include more than one executable file, and you may want to run a container using other than the default command and/or pass some arguments to it.
Luckily, the docker run command is flexible enough to support this:
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Now, let's connect to a remote Redis server using the containerized redis-cli binary.
The Redis server is reachable at 172.16.0.3:6379, and you can use redis-cli -h <host> to connect to it.
Run the redis-cli -h 172.16.0.3 ping command in a redis container:
Hint 2 💡
If the container is failing to connect to Redis,
make sure you use the -h flag with the right IP address and without the port number.
If you really want to specify the port number, you can use the -p flag for that.
Hint 3 💡
While it wouldn't be a strict requirement in a real-world scenario,
the challenge expects you to run the ping command after connecting to the Redis server.
Level up your Server Side game — Join 15,000 engineers who receive insightful learning materials straight to their inbox