首先按照官网运行https://docs.docker.com/engine/installation/linux/ubuntu/#prerequisites
然后不知道怎么用,然后需要
安装Docker-Compose(需要先安装docker)
1. Go to the Compose repository release page on GitHub.
2. Follow the instructions from the release page and run the curl command, which the release page specifies, in your terminal.
【“Permission denied” Run sudo -i, then the two commands below, then exit.】
3. An example command illustrating the format,Apply executable permissions to the binary.Test the installation.
1 2 curl -L https: //github .com /docker/compose/releases/download/1 .8.1 /docker-compose- ` uname -s`-` uname -m` > /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose <br>docker-compose --version
Alternative install options
Install using pip
pip version 6.0 or greater is required
1 pip install docker-composeInstall as a container
1 2 curl -L https: //github .com /docker/compose/releases/download/1 .8.0 /run .sh > /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose最后就可以使用docker了,具体按照下面我转载的一篇博文
本次主要是详细记录Docker1.12在Ubuntu16.04上的安装过程,创建Docker组(避免每次敲命令都需要sudo),Docker常用的基本命令的总结,在容器中运行Hello world,以及创建一个基于Python Flask的web应用容器的全过程。
增加CA证书
wxl@wxl-pc:~$ sudo apt-get install apt-transport-https ca-certificates 1 1添加GPG Key(一种加密手段)
wxl@wxl-pc:~$ sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D 1 1创建docker.list文件
wxl@wxl-pc:~$ sudo vim /etc/apt/sources.list.d/docker.list #添加Ubuntu16.04LST的入口 deb https://apt.dockerproject.org/repo ubuntu-xenial main 123 123再次更新源
wxl@wxl-pc:~$ sudo apt-get update 12 12以防万一,清除过时的源
wxl@wxl-pc:~$ sudo apt-get purge lxc-docker 1 1验证下APT是从正确的库源下载应用的
wxl@wxl-pc:~$ apt-cache policy docker-engine 1 1至此,可见已经配置好了Docker的源
For Ubuntu Trusty, Wily, and Xenial, it’s recommended to install the Linux-image-extra kernel package. The linux-image-extra package allows you use the aufs storage driver可以实现容器间可执行文件和运行库的共享。
更新源,会发现Hit:9 https://apt.dockerproject.org/repo ubuntu-xenial InRelease,也说明Docker在第一步1设置成功。
wxl@wxl-pc:~$ sudo apt-get update 12 12安装 linux-image-extra
wxl@wxl-pc:~$ sudo apt-get install linux-image-extra-$(uname -r) 1 1更新源
wxl@wxl-pc:~$ sudo apt-get update 1 1通过apt命令在线安装docker
wxl@wxl-pc:~$ sudo apt-get install docker-engine 1 1开启docker的守护进程(Docker服务开启)
wxl@wxl-pc:~$ sudo service docker start 1 1国际惯例,用一个Hello world的来测试安装成功
wxl@wxl-pc:~$ sudo docker run hello-world 1 1本地本来没有Hello World镜像,通过Docker源获取到,并成功现实Hello world。 查看正在运行的容器
sudo docker ps -ls 1 1如第一步最后“查看正在运行的容器”如果没有sudo,不以root身份权限运行查看容器命令则会报错Cannot connect to the Docker daemon. Is the docker daemon running on this host?如图
原因: The docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root and other users can access it with sudo. For this reason, docker daemon always runs as the root user.
To avoid having to use sudo when you use the docker command, create a Unix group called docker and add users to it. When the docker daemon starts, it makes the ownership of the Unix socket read/writable by the docker group.
创建用户组docker,可以避免使用sudo 将docker和wxl(王小雷用户名,在创建主机时默认用户名称是ubuntu)添加到一个组内
#默认是ubuntu用户 #wxl@wxl-pc:~$ sudo usermod -aG docker ubuntu # 将wxl的用户添加到docker用户组中,如果多个用户需要用空格隔开 如 wxl wxl1 wxl2用户 wxl@wxl-pc:~$ sudo usermod -aG docker wxl 1234 1234注意需要重新启动计算机或者注销用户再登入,才能生效。这样就不需要使用sudo命令了。 那么,如何将wxl从docker用户组移除? sudo gpasswd -d wxl docker 如何删除刚才创建的docker用户组? sudo groupdel docker 如何创建和删除新用户,如用户newuser sudo adduser newuser sudo userdel newuser
总结,可以看出docker的命令一般为 [sudo] docker [subcommand] [flags] [arguments] 如docker run -i -t ubuntu /bin/bash
运行Python Flask应用(这个过程可能很慢,根据网速而定,因为如果本地没有镜像training/webapp:latest会自动线上获取) 完成 查看运行中打容器通过 docker ps -l
我的是(把Terminal最大化容易识别)
指定端口号,通过Docker -p,如将32769更改为5000 浏览器访问 http://localhost:80 或者http://localhost/
根据Container ID 或者 NAMES 来使用log和top命令,如我执行时产生的CONTAINER ID是83442361e61b,而NAMES是reverent_saha
# 按Ctrl+c结束 查看log wxl@wxl-pc:~$ docker logs -f reverent_saha 12 12 wxl@wxl-pc:~$ docker top reverent_saha 1 1 #返回JSON文档查看配置和状态信息 wxl@wxl-pc:~$ docker inspect reverent_saha #通过特定JSON文档的元素查看特定的配置和状态信息,如IP wxl@wxl-pc:~$ docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' reverent_saha 1234 1234开启/删除/当前的web应用容器
#关闭reverent_saha名称为的web应用容器 wxl@wxl-pc:~$ docker start reverent_saha #删除reverent_saha名称为的web应用容器(注意,容器必须是stop状态) wxl@wxl-pc:~$ docker rm reverent_saha 12345 12345关闭web应用容器,通过docker ps -l 查看容器开启状态
wxl@wxl-pc:~$ docker stop reverent_saha #开启reverent_saha名称为的web应用容器 wxl@wxl-pc:~$ docker ps -l 123 123此时,在打开 http://localhost/ 已经无法链接,因为停止来python flask的web应用。
感谢 王小雷-多面手算一个简单了解吧
概述:基于Docker的TensorFlow机器学习框架搭建和实例源码解读,TensorFlow作为最火热的机器学习框架之一,Docker是的容器,可以很好的结合起来,为机器学习或者科研人员提供便捷的机器学习开发环境,探索人工智能的奥秘,容器随开随用方便快捷。源码解析TensorFlow容器创建和示例程序运行,为热爱机器学者降低学习难度。
默认机器已经装好了Docker(Docker安装和使用可以看我另一篇博文:Ubuntu16.04安装Docker1.12+开发实例+hello world+web应用容器)。