Construct and run a Redis container

Source: Internet
Author: User
Tags docker run install redis

1, first of all, we have to write a basic dockerfile

In any directory

$ VI Dockerfile

Fill in the contents as follows:

From ubuntu:14.04
RUN apt-get Update
RUN apt-get-y Install Redis-server
EXPOSE 6379
entrypoint ["/usr/bin/redis-server"]

2. Build and run the container

After writing the Dockerfile, we can run a command to build a mirror:

$ sudodocker build -t <your username>/redis.

Notice the "." In the back of this command. is indispensable.

After a moment, the image will be created. We then run the Docker Run command to generate the built-in container:

$ sudodocker run --name redis -d <your username>/redis

Where the-d parameter indicates that we want to run the container through the detached mode, which means that the container will continue to run in the background.

3. Create and connect the test Container

We can link the generated Redis container to the new test container by using the Docker run with a-link parameter, so that the test container can access the Redis service without exposing any ports:

$ sudodocker run --link redis:db -i -t ubuntu:14.04 /bin/bash

With the above command, we link the Redis container to the new Ubuntu container and name it db, so that we will only expose the Redis service to this container instead of the larger range.

Next we put the REDIS-CLI in the test Container:

$ apt-get Update
$ apt-get-y Install Redis-server
$ Service Redis-server Stop

Because the-link parameter is used, we find that the environment variable produces some variables that begin with Db_:

$ env| grepDB_

db_name=/condescending_mclean/db
db_port_6379_tcp_port=6379
db_port=tcp://172.17.0.6:6379
db_port_6379_tcp=tcp://172.17.0.6:6379
db_port_6379_tcp_addr=172.17.0.6
Db_port_6379_tcp_proto=tcp

So we can connect to the Redis service through these variables in the test Container:

$ redis-cli -h $DB_PORT_6379_TCP_ADDR

$ redis 172.17.0.6:6379> $ redis 172.17.0.6:6379> set hello world OK $ redis 172.17.0.6:6379> get hello "world" $ redis 172.17.0.6:6379> exit

At this point a Docker container containing the Redis service is created.

Construct and run a Redis container

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.