使用Dockerfile构建Swoole+php7环境

FROM php:7.2.7-cli

RUN apt-get update \
    && apt-get install -y libmemcached-dev zlib1g-dev
    
RUN pecl install redis-4.0.1 \
    && pecl install swoole-4.0.1 \
    && pecl install memcached-3.0.4 \
    && pecl install xdebug-2.6.0 \
    && docker-php-ext-enable redis swoole memcached xdebug
    
COPY . /usr/src/myapp
WORKDIR /usr/src/myapp
CMD [ "php", "-m" ]

构建完环境后,使用方法见:https://blog.haohtml.com/archives/17925

一个docker-compose微服务脚本,自用

容器为swoole+php7

docker-compose.yml

version: '3.6'
services:
  redis:
    image: redis
  web:
    image: cfanbo/swoole4_php7:v1
    depends_on:
      - redis
    links:
      - redis
    volumes:
      - /Users/sxf/sites/msgserve:/usr/src/myapp
    command: "php /usr/src/myapp/src/wx_push_server.php start"

对于 wx_push_server.php文件里redis的主机地址应该写成docker-compose配置文件里的容器服务名(redis)

修改docker默认存储目录(转)

Docker 修改默认存储位置

  • 首先使用 docker info 查看 docker 的基本信息
sudo docker info
Containers: 0
Images: 5
Storage Driver: devicemapper
 Pool Name: docker-253:0-679369-pool
 Pool Blocksize: 65.54 kB
 Backing Filesystem: extfs
 Data file: 
 Metadata file: 
 Data Space Used: 533.9 MB
 Data Space Total: 107.4 GB
 Data Space Available: 106.8 GB
 Metadata Space Used: 954.4 kB
 Metadata Space Total: 2.147 GB
 Metadata Space Available: 2.147 GB
 Udev Sync Supported: true
 Deferred Removal Enabled: false
 Library Version: 1.02.89-RHEL6 (2014-09-01)
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 2.6.32-431.29.2.el6.x86_64
Operating System: <unknown>
CPUs: 1
Total Memory: 853.5 MiB
Name: rhel62build
ID: LIO4:I43U:YFQU:SN45:YOE6:7GTF:6AGX:VSKQ:ICIV:AKWD:3OKQ:HUSC

这是一个新装的docker环境,其中看不出当前docker文件存储的路径。但是docker默认会使用 /var/lib/docker 作为默认存储位置。

  • 停止 Docker 服务
sudo /etc/init.d/docker stop
  • 将原来默认的/var/lib/docker备份一下,然后复制到别的位置并建立一个软链接
cd /var/lib
sudo cp -rf docker docker.bak
sudo cp -rf docker /<my_new_location>/
sudo ln -s /<my_new_location>/docker docker
  • 启动 Docker 服务
sudo /etc/init.d/docker start
  • 最后使用 docker info 查看更新结果
sudo docker info
Containers: 0
Images: 5
Storage Driver: devicemapper
 Pool Name: docker-8:21-393695-pool
 Pool Blocksize: 65.54 kB
 Backing Filesystem: extfs
 Data file: /dev/loop1
 Metadata file: /dev/loop2
 Data Space Used: 533.9 MB
 Data Space Total: 107.4 GB
 Data Space Available: 15.33 GB
 Metadata Space Used: 954.4 kB
 Metadata Space Total: 2.147 GB
 Metadata Space Available: 2.147 GB
 Udev Sync Supported: true
 Deferred Removal Enabled: false
 Data loop file: /build/docker/devicemapper/devicemapper/data
 Metadata loop file: /build/docker/devicemapper/devicemapper/metadata
 Library Version: 1.02.89-RHEL6 (2014-09-01)
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 2.6.32-431.29.2.el6.x86_64
Operating System: <unknown>
CPUs: 1
Total Memory: 853.5 MiB
Name: rhel62build
ID: LIO4:I43U:YFQU:SN45:YOE6:7GTF:6AGX:VSKQ:ICIV:AKWD:3OKQ:HUSC

转载请以链接形式标明本文地址
本文地址:http://blog.csdn.net/kongxx/article/details/50310653

使用docker-compose 快速创建一个mysql 数据库容器

//创建一个独立的容器目录

mkdir docker-db
cd docker-db

前提、创建 docker Compose 配置文件
#vi docker-compose.yml 文件,内容如下

version: '3.6'
services: 

    db:
        image: hub.c.163.com/library/mysql:5.7
        restart: always
        environment:
            MYSQL_ROOT_PASSWORD: 123456
            MYSQL_DATABASE: wordpress
            MYSQL_USER: root
            MYSQL_PASSWORD: 123456
            MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
        ports:
            - "33061:3306"

image也可以直接写mysql:5.7 或者mysql:latest,不指定获取地址。
上面的 ports 这一块,是指宿主机端口号:容器端口号。在使用的时候,直接访问本机的 33061 端口即可。端口号前也可以指定一个固定的IP 地址。
Compose file version 3 reference:https://docs.docker.com/compose/compose-file/

一、创建并启动容器

$docker-composer up

在 docker-composr.yml 所在的目录里,执行上面的命令,此时会自动从远程服务器拉取容器所需的信息。这时窗口一直处于运行状态,我们通过添加
-d
参数,来实现后台服务运行。

二、停止关闭容器

$ docker-compose stop

关闭后,容器文件仍然在磁盘上存在,重新执行 docker-compose start 即可启动。

三、删除容器

docker-compose rm

上面的命令可以将已经停止运行的容器进行删除,也可以将停止和删除用一条命令代替

docker-compose down

更多命令请执行 docker-compose -h 查看。

Docker Machine 简介

一句话概括的话就是 Docker Machine是一个可以方便对多个宿主服务器中的多个容器进行管理的工具。

Docker 与 Docker Machine 的区别 https://www.cnblogs.com/sparkdev/p/7066789.html

Docker Machine 工具出现的意义 https://www.2cto.com/net/201707/660864.html

Docker Machine 用法 http://www.linuxidc.com/Linux/2017-06/145232.htm

Docker Machine 命令 http://blog.csdn.net/warren_1992/article/details/51451522

Mac平台上Docker安装与使用 http://blog.csdn.net/warren_1992/article/details/51451522

windows平台在dos下执行docker pull 命令出错

这里docker Machine 是安装和管理 Docker 的工具(用来代替Boot2Docker,对于个人玩的话,不建议使用docker Machine,毕竟多了一个虚拟层,不如直接使用当前物理机器作为容器的宿主机)

$ docker pull gitlab/gitlab-ce:latest

Warning: failed to get default registry endpoint from daemon (error during connect: Get http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.33/info: open //./pipe/docker_engine: The system cannot find the file specified. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running.). Using system default: https://index.docker.io/v1/
error during connect: Post http://%2F%2F.%2Fpipe%2Fdocker_engine/v1.33/images/create?fromImage=gitlab%2Fgitlab-ce&tag=latest: open //./pipe/docker_engine: The system cannot find the file specified. In the default daemon configuration on Windows, the docker client must be run elevated to connect. This error may also indicate that the docker daemon is not running.

解决方法:打开新窗口后执行(

docker-machine env

根据提示运行命令

@FOR /f "tokens=*" %i IN ('docker-machine env default') DO @%i

default 是docker-machine的name,可以通过docker-machine -ls 查看。

如果还提示这个错误,说明没有启用 default ,执行下面的命令

D:\docker
$ docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
default - virtualbox Stopped Unknown

如果为stopped状态,则需要启用一下

$ docker-machine start default
Starting "default"...
(default) Check network to re-create if needed...
(default) Windows might ask for the permission to configure a dhcp server. Sometimes, such confirmation window is minimized in the taskbar.
(default) Waiting for an IP...
Machine "default" was started.
Waiting for SSH to be available...
Detecting the provisioner...
Started machines may have new IP addresses. You may need to re-run the `docker-machine env` command.

最后再执行

$ docker pull hub-mirror.c.163.com/gitlab/gitlab-ce:latest
latest: Pulling from gitlab/gitlab-ce
1be7f2b886e8: Pull complete
6fbc4a21b806: Pull complete
c71a6f8e1378: Pull complete
4be3072e5a37: Pull complete
06c6d2f59700: Pull complete
3e236075b07f: Pull complete
9d3aa9a75297: Pull complete
1fad4f75154b: Pull complete
5383bef86102: Pull complete
7343d4ab63b3: Pull complete
7f250f1b8a34: Downloading [==================> ] 157.4MB/415.4MB