Docker中⽂社区⽂档:https://www.docker.org.cn/index.html
Docker 是⼀个开源的软件部署解决⽅案。
Docker 也是轻量级的应⽤容器框架。
Docker 可以打包、发布、运⾏任何的应⽤。
Docker 就像⼀个盒⼦,⾥⾯可以装很多物件,如果需要某些物件,可以直接将该盒⼦拿⾛,⽽不需要从该盒⼦中⼀件⼀件的取。
Docker 是⼀个客户端-服务端(C/S)架构程序。客户端只需要向服务端发出请求,服务端处理完请求后会返回结果。
Docker 包括三个基本概念:
镜像(Image)
Docker的镜像概念类似于虚拟机⾥的镜像,是⼀个只读的模板,⼀个独⽴的⽂件系统,包括运⾏容器所需的数据,可以⽤来创建新的容器。
例如:⼀个镜像可以包含⼀个完整的 ubuntu 操作系统环境,⾥⾯仅安装了MySQL或⽤户需要的其它应⽤程序。
容器(Container)
Docker容器是由Docker镜像创建的运⾏实例,类似VM虚拟机,⽀持启动,停⽌,删除等。
每个容器间是相互隔离的,容器中会运⾏特定的应⽤,包含特定应⽤的代码及所需的依赖⽂件。
仓库(Repository)
Docker的仓库功能类似于Github,是⽤于托管镜像的。
Docker官方安装文档:https://docs.docker.com/engine/install/ubuntu/#prerequisites
1.更新 apt 包索引
$ sudo apt-get update
2.安装 apt 依赖包,⽤于通过HTTPS来获取仓库
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
3.添加 Docker 的官⽅ GPG 密钥
$ curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
4.通过搜索指纹的后8个字符,验证您现在是否拥有带有指纹的密钥
$ sudo apt-key fingerprint 0EBFCD88
5.使⽤以下指令设置稳定版仓库
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
6.安装 Docker Engine-Community
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
7.测试是否安装成功
$ sudo docker run hello-world
# 出现如下提示
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest:
sha256:c3b4ada4687bbaa170745b3e4dd8ac3f194ca95b2d0518b417fb47e5879d
9b5f
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working
correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the
Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which
runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client,
which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container
with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/get-started/
8.查看当前安装版本
$ docker -v
Docker version 23.0.1, build a5ee5
9.启动与停⽌
安装完成Docker后,默认已经启动了docker服务。
# 启动docker
$ sudo service docker start
# 重启docker
$ sudo service docker restart
# 停⽌docker
$ sudo service docker stop
1.镜像列表
$ sudo docker image ls
或
$ sudo docker images
➜ ~ sudo docker image ls
[sudo] password for sanha:
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest feb5d9fea6a5 17 months ago 13.3kB
* REPOSITORY:镜像所在的仓库名称
* TAG:镜像标签
* IMAGEID:镜像ID
* CREATED:镜像的创建⽇期(不是获取该镜像的⽇期)
* SIZE:镜像⼤⼩
2.从仓库拉取镜像
$ sudo docker image pull 镜像名称 或者 sudo docker image pull
library/镜像名称
$ sudo docker image pull ubuntu 或者 sudo docker image pull
library/ubuntu
$ sudo docker image pull ubuntu:18.04 或者 sudo docker image pull
library/ubuntu:18.04
3.删除镜像
$ sudo docker image rm 镜像名或镜像ID
$ sudo docker image rm hello-world
$ sudo docker image rm fce289e99eb9
1.容器列表
# 查看正在运⾏的容器
$ sudo docker container ls
# 查看所有的容器
$ sudo docker container ls --all
2.创建容器
$ sudo docker run [option] 镜像名 [向启动容器中传⼊的命令]
常⽤可选参数说明:
* -i 表示以《交互模式》运⾏容器。
* -t 表示容器启动后会进⼊其命令⾏。加⼊这两个参数后,容器创建就能登录进去。即分
配⼀个伪终端。
* --name 为创建的容器命名。
* -v 表示⽬录映射关系,即宿主机⽬录:容器中⽬录。注意:最好做⽬录映射,在宿主机上
做修改,然后共享到容器上。
* -d 会创建⼀个守护式容器在后台运⾏(这样创建容器后不会⾃动登录容器)。
* -p 表示端⼝映射,即宿主机端⼝:容器中端⼝。
* --network=host 表示将主机的⽹络环境映射到容器中,使容器的⽹络与主机相同。
3.交互式容器
$ sudo docker run -it --name=ubuntu1 ubuntu /bin/bash
在容器中可以随意执⾏linux命令,就是⼀个ubuntu的环境。
当执⾏ exit 命令退出时,该容器随之停⽌。
4.守护式容器
# 开启守护式容器
$ sudo docker run -dit --name=ubuntu2 ubuntu
# 进⼊到容器内部交互环境
$ sudo docker exec -it 容器名或容器id 进⼊后执⾏的第⼀个命令
$ sudo docker exec -it ubuntu2 /bin/bash
如果对于⼀个需要⻓期运⾏的容器来说,我们可以创建⼀个守护式容器。
在容器内部执⾏ exit 命令退出时,该容器也随之停⽌。
5.停⽌和启动容器
# 停⽌容器
$ sudo docker container stop 容器名或容器id
# kill掉容器
$ sudo docker container kill 容器名或容器id
# 启动容器
$ sudo docker container start 容器名或容器id
查看运行的容器
sudo docker ps -a
6.删除容器
正在运⾏的容器⽆法直接删除。
$ sudo docker container rm 容器名或容器id
7.容器制作成镜像
为保证已经配置完成的环境可以重复利⽤,我们可以将容器制作成镜像。
# 将容器制作成镜像
$ sudo docker commit 容器名 镜像名
# 镜像打包备份
$ sudo docker save -o 保存的⽂件名 镜像名
# 镜像解压
$ sudo docker load -i ⽂件路径/备份⽂件
我想为Heroku构建一个Rails3应用程序。他们使用Postgres作为他们的数据库,所以我通过MacPorts安装了postgres9.0。现在我需要一个postgresgem并且共识是出于性能原因你想要pggem。但是我对我得到的错误感到非常困惑当我尝试在rvm下通过geminstall安装pg时。我已经非常明确地指定了所有postgres目录的位置可以找到但仍然无法完成安装:$envARCHFLAGS='-archx86_64'geminstallpg--\--with-pg-config=/opt/local/var/db/postgresql90/defaultdb/po
我打算为ruby脚本创建一个安装程序,但我希望能够确保机器安装了RVM。有没有一种方法可以完全离线安装RVM并且不引人注目(通过不引人注目,就像创建一个可以做所有事情的脚本而不是要求用户向他们的bash_profile或bashrc添加一些东西)我不是要脚本本身,只是一个关于如何走这条路的快速指针(如果可能的话)。我们还研究了这个很有帮助的问题:RVM-isthereawayforsimpleofflineinstall?但有点误导,因为答案只向我们展示了如何离线在RVM中安装ruby。我们需要能够离线安装RVM本身,并查看脚本https://raw.github.com/wayn
我有一个奇怪的问题:我在rvm上安装了rubyonrails。一切正常,我可以创建项目。但是在我输入“railsnew”时重新启动后,我有“程序'rails'当前未安装。”。SystemUbuntu12.04ruby-v"1.9.3p194"gemlistactionmailer(3.2.5)actionpack(3.2.5)activemodel(3.2.5)activerecord(3.2.5)activeresource(3.2.5)activesupport(3.2.5)arel(3.0.2)builder(3.0.0)bundler(1.1.4)coffee-rails(
我刚刚为fedora安装了emacs。我想用emacs编写ruby。为ruby提供代码提示、代码完成类型功能所需的工具、扩展是什么? 最佳答案 ruby-mode已经包含在Emacs23之后的版本中。不过,它也可以通过ELPA获得。您可能感兴趣的其他一些事情是集成RVM、feature-mode(Cucumber)、rspec-mode、ruby-electric、inf-ruby、rinari(用于Rails)等。这是我当前用于Ruby开发的Emacs配置:https://github.com/citizen428/emacs
我正在尝试在我的centos服务器上安装therubyracer,但遇到了麻烦。$geminstalltherubyracerBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingtherubyracer:ERROR:Failedtobuildgemnativeextension./usr/local/rvm/rubies/ruby-1.9.3-p125/bin/rubyextconf.rbcheckingformain()in-lpthread...yescheckingforv8.h...no***e
我的最终目标是安装当前版本的RubyonRails。我在OSXMountainLion上运行。到目前为止,这是我的过程:已安装的RVM$\curl-Lhttps://get.rvm.io|bash-sstable检查已知(我假设已批准)安装$rvmlistknown我看到当前的稳定版本可用[ruby-]2.0.0[-p247]输入命令安装$rvminstall2.0.0-p247注意:我也试过这些安装命令$rvminstallruby-2.0.0-p247$rvminstallruby=2.0.0-p247我很快就无处可去了。结果:$rvminstall2.0.0-p247Search
我实际上是在尝试使用RVM在我的OSX10.7.5上更新ruby,并在输入以下命令后:rvminstallruby我得到了以下回复:Searchingforbinaryrubies,thismighttakesometime.Checkingrequirementsforosx.Installingrequirementsforosx.Updatingsystem.......Errorrunning'requirements_osx_brew_update_systemruby-2.0.0-p247',pleaseread/Users/username/.rvm/log/138121
由于fast-stemmer的问题,我很难安装我想要的任何rubygem。我把我得到的错误放在下面。Buildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingfast-stemmer:ERROR:Failedtobuildgemnativeextension./System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/rubyextconf.rbcreatingMakefilemake"DESTDIR="cleanmake"DESTDIR=
当我尝试安装Ruby时遇到此错误。我试过查看this和this但无济于事➜~brewinstallrubyWarning:YouareusingOSX10.12.Wedonotprovidesupportforthispre-releaseversion.Youmayencounterbuildfailuresorotherbreakages.Pleasecreatepull-requestsinsteadoffilingissues.==>Installingdependenciesforruby:readline,libyaml,makedepend==>Installingrub
我试过重新启动apache,缓存的页面仍然出现,所以一定有一个文件夹在某个地方。我没有“公共(public)/缓存”,那么我还应该查看哪些其他地方?是否有一个URL标志也可以触发此效果? 最佳答案 您需要触摸一个文件才能清除phusion,例如:touch/webapps/mycook/tmp/restart.txt参见docs 关于ruby-如何在Ubuntu中清除RubyPhusionPassenger的缓存?,我们在StackOverflow上找到一个类似的问题: