使用ssh登录linux 内部docker容器

#拉取docker ubuntu 镜像
docker pull ubuntu
#查看镜像ID
docker images

[root@VM_0_4_centos ~]# docker images
REPOSITORY                            TAG                 IMAGE ID            CREATED             SIZE
docker.io/ubuntu                      latest              4e2eef94cd6b        4 weeks ago         73.9 MB

#通过镜像 IMAGE ID 创建docker容器,将32端口映射到docker 22端口,用于ssh登录,81映射到80作为web备用端口

docker run -it -d --name=ubuntu -p 32:22 -p 81:80 4e2eef94cd6b /bin/bash
获取docker容器 CONTAINER ID
docker ps

[root@VM_0_4_centos ~]# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                                                                            NAMES
24cade70f910        4e2eef94cd6b        "/bin/bash"              2 hours ago         Up 2 hours          0.0.0.0:32->22/tcp, 0.0.0.0:81->80/tcp                                                           ubuntu
#进入docker容器
docker exec -it 24cade70f910 /bin/bash
apt update
#然后通过passwd命令修改root的密码。
passwd
#安装openssh-server:  
apt install -y openssh-server
#安装vim
apt install -y vim
vim /etc/ssh/sshd_config

 添加PermitRootLogin yes 
 修改UsePAM no
保存
重启ssh
service ssh start
然后通过ssh工具 使用32端口即可登录,如果你使用阿里云或者腾讯云,需要登录服务商后台安全策略放行32等其他端口

phpwebdriver+ docker-selenium+linux实现网络爬虫

linux上需要安装docker服务,如果没有安装请看前面的文章
#拉取docker 镜像 
docker pull selenium/standalone-chrome:4.0.0-alpha-7-prerelease-20200826

#创建selenium docker容器
docker run -d -p 4444:4444 --name=selenium -v /dev/shm:/dev/shm selenium/standalone-chrome:4.0.0-alpha-7-prerelease-20200826

#查看容器状态
docker ps

搭建php环境、安装compser此处不赘述

composer require php-webdriver/webdriver
<?php
/**
 * Created by PhpStorm.
 * User: lizhiguo
 * Date: 2020/8/31
 * Time: 10:05
 */
require __DIR__ . '/vendor/autoload.php';
use \Facebook\WebDriver\Remote\RemoteWebDriver;
use \Facebook\WebDriver\Remote\DesiredCapabilities;
use \Facebook\WebDriver\Chrome\ChromeOptions;
$host='http://127.0.0.1:4444';
$desiredCapabilities = DesiredCapabilities::chrome();

// Disable accepting SSL certificates
$desiredCapabilities->setCapability('acceptSslCerts', false);

// Run headless firefox

$chromeOptions = new ChromeOptions();
$chromeOptions->addArguments(['--no-sandbox', '--headless']);

$desiredCapabilities->setCapability(ChromeOptions::CAPABILITY_W3C, $chromeOptions);


$driver = RemoteWebDriver::create($host, $desiredCapabilities);


for ($i=1;$i<=14;$i++){
	echo $url="https://www.amazon.com/s?k=keyboard&page=".$i."&qid=".time()."&ref=sr_pg_3";
	$driver->get($url);
//	$chromeOptions->getCookies($url);
	print_r($source=$driver->getPageSource());
	file_put_contents($i.'.html',$source);
}

//$driver->manage()->getCookies();


$driver->quit();
https://php-webdriver.github.io/php-webdriver/latest/Facebook/WebDriver/Chrome/ChromeDriver.html