Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to use link in docker

Shulou Source: shulou.com Published: 2022-06-01 17:30:32 09月27日 Update

This article introduces how to use link in docker, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Create a dockerfile. In this article, the dockerfile is named Dockerfile_memcached (the file name can be defined at will):

# Memcached## VERSION 2.2FROM ubuntu:12.04MAINTAINER Marker.King # make sure the package repository is up to dateRUN echo "deb http://mirrors.aliyun.com/ubuntu precise main universe" > / etc/apt/sources.listRUN apt-get update# install memcachedRUN apt-get install-y memcached# Launch memcached when launching the containerENTRYPOINT ["memcached"] # run memcached as the daemon userUSER daemon# expose memcached portEXPOSE 11211

Build an image based on dockerfile:

$docker build-t memecached-

< Dockerfile_memcached 使用构建的镜像启动容器: $ docker run -d -name memcached_service memcached 根据镜像启动一个shell交互方式的容器,连接memcached服务,ubuntu_with_pip是我预先安装了pip的一个镜像: $ docker run -i -t -link memcached_service:db ubuntu_with_pip:12.04 /bin/bash 查看shell交互容器的环境变量: root@665f1bdc5913:/# envHOSTNAME=665f1bdc5913DB_NAME=/compassionate_pasteur/dbTERM=xtermDB_PORT=tcp://172.17.0.2:11211DB_PORT_11211_TCP_PROTO=tcpDB_PORT_11211_TCP_ADDR=172.17.0.2PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binPWD=/SHLVL=1HOME=/DB_PORT_11211_TCP_PORT=11211DB_PORT_11211_TCP=tcp://172.17.0.2:11211container=lxc_=/usr/bin/env 安装python-memcached,并通过python测试是否能够正常使用: root@665f1bdc5913:/# pip install python-memcachedroot@665f1bdc5913:/# python>

> > import memcache > mc = memcache.Client (["172.17.0.2 print 11211"], debug=0) > mc.set ("MDM", "Marker.King") True > value = mc.get ("MDM") > print (value) Marker.King about how to use link in docker is shared here. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Images containers content more help good interests variables guys buddies files file names articles methods environment knowledge articles references services tests Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL MariaDB Huawei macOS Microsoft