继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

docker常用命令

aluckdog
关注TA
已关注
手记 307
粉丝 68
获赞 392

搜索docker映像

$ docker search ubuntu
NAME                                                      DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
ubuntu                                                    Ubuntu is a Debian-based Linux operating sys…   7265                [OK]
dorowu/ubuntu-desktop-lxde-vnc                            Ubuntu with openssh-server and NoVNC            161                                     [OK]
rastasheep/ubuntu-sshd                                    Dockerized SSH service, built on top of offi…   130                                     [OK]
ansible/ubuntu14.04-ansible                               Ubuntu 14.04 LTS with ansible                   90                                      [OK]
ubuntu-upstart                                            Upstart is an event-based replacement for th…   81                  [OK]
neurodebian                                               NeuroDebian provides neuroscience research s…   43                  [OK]
ubuntu-debootstrap                                        debootstrap --variant=minbase --components=m…   35                  [OK]1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5      ubuntu-16-nginx-php-phpmyadmin-mysql-5          25                                      [OK]
nuagebec/ubuntu                                           Simple always updated Ubuntu docker images w…   22                                      [OK]
tutum/ubuntu                                              Simple Ubuntu docker images with SSH access     18ppc64le/ubuntu                                            Ubuntu is a Debian-based Linux operating sys…   11i386/ubuntu                                               Ubuntu is a Debian-based Linux operating sys…   91and1internet/ubuntu-16-apache-php-7.0                    ubuntu-16-apache-php-7.0                        6                                       [OK]
darksheer/ubuntu                                          Base Ubuntu Image -- Updated hourly             3                                       [OK]
codenvy/ubuntu_jdk8                                       Ubuntu, JDK8, Maven 3, git, curl, nmap, mc, …   3                                       [OK]1and1internet/ubuntu-16-apache                            ubuntu-16-apache                                3                                       [OK]1and1internet/ubuntu-16-nginx-php-5.6-wordpress-4         ubuntu-16-nginx-php-5.6-wordpress-4             2                                       [OK]1and1internet/ubuntu-16-nginx-php-phpmyadmin-mariadb-10   ubuntu-16-nginx-php-phpmyadmin-mariadb-10       2                                       [OK]1and1internet/ubuntu-16-nginx                             ubuntu-16-nginx                                 2                                       [OK]
pivotaldata/ubuntu                                        A quick freshening-up of the base Ubuntu doc…   1pivotaldata/ubuntu-gpdb-dev                               Ubuntu images for GPDB development              01and1internet/ubuntu-16-sshd                              ubuntu-16-sshd                                  0                                       [OK]
smartentry/ubuntu                                         ubuntu with smartentry                          0                                       [OK]
ossobv/ubuntu                                             Custom ubuntu image from scratch (based on o…   01and1internet/ubuntu-16-healthcheck                       ubuntu-16-healthcheck                           0                                       [OK]

下载一个映像(image)

docker pull ubuntu

如果想下载特定版本,需要加:14.04

docker pull ubuntu:14.04

运行映像

运行映像就会得到一个容器(Container)

docker run ubuntu /bin/echo "haha"

运行映像并得到一个终端

docker run -i -t ubuntu /bin/bash

-t:在新容器内指定一个伪终端或终端。
-i:允许你对容器内的标准输入 (STDIN) 进行交互。

使用docker运行交互式的python

首先要有python,如python:3.5

docker pull python:3.5

然后运行, 可以进入交互环境
docker run -i -t  python:3.5 python
前面的python是image的名字,后面的是python
这样就会进入python交互状态。

运行py文件

一个需要知道的概念是, docker容器不能持久的保存文件,退出就会消失。
所以,需要将本地的一个文件夹绑定到docker中的系统里。

  • 建立一个目录mydir

  • 放入一个helloworld.py到mydir中,内容为 print("hah")

  • 执行以下命令

docker run  -v $PWD/mydir:/home/myapp  -w /home/myapp python:3.5 python helloworld.py

其中$PWD为当前目录。 -v 是将当前目录的mydir文件,映射到 /home/myapp目录。 -w 是制定当前目录。 这个命令中是将自己映射的myapp设为当前目录。 随后执行python helloworld.py命令。



作者:taiji1985
链接:https://www.jianshu.com/p/1ded08d20daa

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP