映射端口

-d 后台执行

-p映射端口

--privileged 可以使用systemctl

# docker run --privileged -d -p 9000:80 jiqing9006/centos:httpd /sbin/init
e2e33ac1fb2acdef86c995c79eb746fb552417b112210bc5353de74a2f63e4e7

访问容器

root@ThinkPad:/home/jiqing# docker ps -q
e2e33ac1fb2a
root@ThinkPad:/home/jiqing# docker exec -it e2e33ac1fb2a /bin/bash

开启httpd服务

systemctl restart httpd

外部访问

$ sudo netstat -anpl|grep :9000
tcp6 0 0 :::9000 :::* LISTEN 10352/docker-proxy

修改容器密码,默认root的密码是随机的,需要修改一下

[root@e2e33ac1fb2a /]# passwd root
Changing password for user root.
New password:
BAD PASSWORD: The password is shorter than 8 characters
Retype new password:
passwd: all authentication tokens updated successfully.

配置完密码,把22端口映射出去,就可以远程访问了。

安装sshd

[root@e2e33ac1fb2a /]# yum install openssh-server
Loaded plugins: fastestmirror, ovl
base | 3.6 kB 00:00
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.zju.edu.cn
* updates: mirror.bit.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package openssh-server.x86_64 0:7.4p1-13.el7_4 will be installed
--> Processing Dependency: openssh = 7.4p1-13.el7_4 for package: openssh-server-7.4p1-13.el7_4.x86_64
--> Processing Dependency: fipscheck-lib(x86-64) >= 1.3.0 for package: openssh-server-7.4p1-13.el7_4.x86_64
--> Processing Dependency: libwrap.so.0()(64bit) for package: openssh-server-7.4p1-13.el7_4.x86_64
--> Processing Dependency: libfipscheck.so.1()(64bit) for package: openssh-server-7.4p1-13.el7_4.x86_64
--> Running transaction check
---> Package fipscheck-lib.x86_64 0:1.4.1-6.el7 will be installed
--> Processing Dependency: /usr/bin/fipscheck for package: fipscheck-lib-1.4.1-6.el7.x86_64
---> Package openssh.x86_64 0:7.4p1-13.el7_4 will be installed
---> Package tcp_wrappers-libs.x86_64 0:7.6-77.el7 will be installed
--> Running transaction check
---> Package fipscheck.x86_64 0:1.4.1-6.el7 will be installed
--> Finished Dependency Resolution Dependencies Resolved ================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
openssh-server x86_64 7.4p1-13.el7_4 updates 458 k
Installing for dependencies:
fipscheck x86_64 1.4.1-6.el7 base 21 k
fipscheck-lib x86_64 1.4.1-6.el7 base 11 k
openssh x86_64 7.4p1-13.el7_4 updates 509 k
tcp_wrappers-libs x86_64 7.6-77.el7 base 66 k Transaction Summary
================================================================================
Install 1 Package (+4 Dependent packages) Total download size: 1.0 M
Installed size: 3.0 M
Is this ok [y/d/N]: y
Downloading packages:
(1/5): fipscheck-1.4.1-6.el7.x86_64.rpm | 21 kB 00:00
(2/5): openssh-7.4p1-13.el7_4.x86_64.rpm | 509 kB 00:00
(3/5): fipscheck-lib-1.4.1-6.el7.x86_64.rpm | 11 kB 00:00
(4/5): openssh-server-7.4p1-13.el7_4.x86_64.rpm | 458 kB 00:00
(5/5): tcp_wrappers-libs-7.6-77.el7.x86_64.rpm | 66 kB 00:00
--------------------------------------------------------------------------------
Total 1.2 MB/s | 1.0 MB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : fipscheck-lib-1.4.1-6.el7.x86_64 1/5
Installing : fipscheck-1.4.1-6.el7.x86_64 2/5
Installing : openssh-7.4p1-13.el7_4.x86_64 3/5
Installing : tcp_wrappers-libs-7.6-77.el7.x86_64 4/5
Installing : openssh-server-7.4p1-13.el7_4.x86_64 5/5
Verifying : openssh-7.4p1-13.el7_4.x86_64 1/5
Verifying : openssh-server-7.4p1-13.el7_4.x86_64 2/5
Verifying : fipscheck-1.4.1-6.el7.x86_64 3/5
Verifying : fipscheck-lib-1.4.1-6.el7.x86_64 4/5
Verifying : tcp_wrappers-libs-7.6-77.el7.x86_64 5/5 Installed:
openssh-server.x86_64 0:7.4p1-13.el7_4 Dependency Installed:
fipscheck.x86_64 0:1.4.1-6.el7 fipscheck-lib.x86_64 0:1.4.1-6.el7
openssh.x86_64 0:7.4p1-13.el7_4 tcp_wrappers-libs.x86_64 0:7.6-77.el7 Complete!

启动sshd

[root@e2e33ac1fb2a /]# systemctl restart sshd

外部ssh访问

root@ThinkPad:/home/jiqing# ssh root@172.17.0.1
root@172.17.0.1's password:
Last login: Sun May 6 16:55:21 2018 from gateway
[root@e2e33ac1fb2a ~]#

更新镜像

root@ThinkPad:/home/jiqing# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e2e33ac1fb2a jiqing9006/centos:httpd "/sbin/init" 16 minutes ago Up 16 minutes 0.0.0.0:9000->80/tcp peaceful_kilby
root@ThinkPad:/home/jiqing# docker commit e2e33ac1fb2a jiqing9006/centos:httpd
sha256:0824bbef68beae4530c9b6e8997bb4685339865bd521ec1262ffdacf6a9dd0f8
root@ThinkPad:/home/jiqing# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
jiqing9006/centos httpd 0824bbef68be 7 seconds ago 496MB

上传到hub中

root@ThinkPad:/home/jiqing# docker push jiqing9006/centos:httpd
The push refers to repository [docker.io/jiqing9006/centos]
611121574145: Pushed
79655226b20c: Layer already exists
6572279f7725: Layer already exists
a4fc816997be: Layer already exists
43e653f84b79: Layer already exists
httpd: digest: sha256:47ae6da07149aecba4944351e4f61fa887b52ad4fad16e6e1e8c4fda0a457151 size: 1367

hub库会更新哦!

docker映射端口与ssh访问或容器访问的更多相关文章

  1. docker 映射端口穿透内置防火墙

    一.问题现象 1.现象举例: # 自制的springboot项目的dockerfile # springboot 其实就是一个简单的hello-world程序,写了一个HelloController ...

  2. docker发现端口是tcp6的 导致无法访问前端

    最近偶尔发现一个比较奇怪的现象,netstat 查看监听的服务端口时,却只显示了 tcp6 的监控, 但是服务明明是可以通过 tcp4 的 ipv4 地址访问的,那为什么没有显示 tcp4 的监听呢? ...

  3. 聊聊docker那些端口问题

    今天来系统聊一聊docker的端口,常见的有容器内程序端口.容器端口.主机端口.Dockerfile中EXPOSE端口.docker-compose和docker run中的port等. 貌似很多端口 ...

  4. Docker基础-端口映射与容器互联

    1.端口映射实现访问容器 1.从外部访问容器应用 在启动容器的时候,如果不指定对应的参数,在容器外部是无法通过网络来访问容器内部的网络应用和服务的. 当容器中运行一些网络应用,要让外部访问这些应用时, ...

  5. 解决docker容器启动时候无法映射端口的问题

    当我们停止防火墙后,docker容器启动映射端口可能无法映射端口,这个时候需要重建docker0网桥. 详细的错误是这样的: docker: Error response from daemon: d ...

  6. docker容器添加对外映射端口

    一般在运行容器时,我们都会通过参数 -p(使用大写的-P参数则会随机选择宿主机的一个端口进行映射)来指定宿主机和容器端口的映射,例如 docker run -it -d --name [contain ...

  7. Docker 更改容器映射端口

    1.编辑容器的配置文件进行更改端口: docker run 运行启动时 -p 可以指定容器启动映射端口 ( ) 可以编辑配置文件 进行修改:(需要重启docker 服务 不止是是容器 才能生效.只能重 ...

  8. docker学习端口映射---第二章节

    一.运行一个web应用 首先,下载一个docker镜像: [root@k8s-01 ~]# docker pull training/webapp 运行webapp的容器: [root@k8s-01 ...

  9. docker之容器访问和网络连接(三)

    前言 当一台服务器上部署了多个应用容器,它们直接可能需要相互通信,比如web应用容器需要访问mysql数据库容器. 主机访问容器 通过映射端口的形式我们可以在外部访问容器内的服务 # 将主机的127. ...

随机推荐

  1. 「 HDU P4734 」 F(x)

    # 题目大意 对于一个数 $x$,它的每一位数字分别是 $A_{n}A_{n-1}A_{n-2}\cdots A_{2}A_{1}$,定义其权重 $f(x)=\sum_{i=1}^{n}\left(A ...

  2. mysql批量插值

    将查询结果集插入到表中(适用批量插值) 将结果集插入 不需要添加VALUES INSERT INTO `erp`.`role_menu` (`ROLEUUID`, `MENUUUID`) (SELEC ...

  3. Python列表、元组、字典、集合的内置使用方法

    列表: 是一种可以存储多个值得数据容器 内容是有序的 可以存储任何数据类型 可以存储重复的元素 是可变类型(当内容发生变化时id不变) 元组: 也是一种可以存储多个值得数据容器 元组中的元素不可以被修 ...

  4. assert.throws()函数详解

    assert.throws(block[, error][, message]) Node.js FS模块方法速查 期望 block 函数抛出一个错误. 如果指定 error,它可以是一个构造函数.正 ...

  5. python的学习之路(三)

    一.set集合#!/usr/bin/env python# *_*coding:utf-8 *_*# Author: harson old_dict = { "#1": {'hos ...

  6. UVa 712 S-Trees(二进制转换 二叉树叶子)

    题意: 给定一颗n层的二叉树的叶子, 然后给定每层走的方向, 0代表左边, 1代表右边, 求到达的是那一个叶子. 每层有一个编号, 然后n层的编号是打乱的, 但是给的顺序是从1到n. 分析: 先用一个 ...

  7. 冒泡排序 and 选择排序 变量打印斐波拉契数列 and 数组打印斐波拉契数列

    1 排序 1.1 冒泡排序 #include <stdio.h> int main() { ]; printf("input six int numbers:\n"); ...

  8. java-得到字符串中出现次数最最多的字符,并打印出字符以及出现次数

    最近面试总被面试到,整理出几种方式(有参考别人的部分) /** * java一个字符串中出现次数最多的字符以及次数 * @param args */ public static void main(S ...

  9. [SCOI2008]奖励关 - 状压动规 - 概率与期望

    Description 你正在玩你最喜欢的电子游戏,并且刚刚进入一个奖励关.在这个奖励关里,系统将依次随机抛出k次宝物,每次你都可以选择吃或者不吃(必须在抛出下一个宝物之前做出选择,且现在决定不吃的宝 ...

  10. SpringBoot Data JPA 关联表查询的方法

    SpringBoot Data JPA实现 一对多.多对一关联表查询 开发环境 IDEA 2017.1 Java1.8 SpringBoot 2.0 MySQL 5.X 功能需求 通过关联关系查询商店 ...