1,启动容器
1. 启动一个docker容器:
docker start 容器id/容器名称
2. 启动多个docker容器:
docker start 容器id/容器名称 容器id/容器名称 容器id/容器名称...
sudo docker start gracious_cannon
1,当前容器已经启动,怎么进入呢?
dokcer ps -a 查询正在运行的container
docker exec -it 容器ID /bin/bash 进入容器
exit 退出容器
crnn@crnn-System-Product-Name:~$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0bf9637d4edf registry.baidubce.com/paddlepaddle/serving:0.9.0-cuda10.1-cudnn7-devel "/bin/bash" 3 hours ago Up 13 seconds 22/tcp serene_murdock
crnn@crnn-System-Product-Name:~$ sudo docker exec -it 0bf9637d4edf /bin/bash
λ 0bf9637d4edf /home cd PaddleOCR/deploy/pdserving/
λ 0bf9637d4edf /home/PaddleOCR/deploy/pdserving {release/2.5} python3.7 web_service.py &>log.txt &
[1] 40
λ 0bf9637d4edf /home/PaddleOCR/deploy/pdserving {release/2.5}
λ 0bf9637d4edf /home/PaddleOCR/deploy/pdserving {release/2.5} python3.7 pipeline_http_client.py
-----进入步骤
sudo docker exec -it 0bf9637d4edf /bin/bash
cd PaddleOCR/deploy/pdserving/
python3.7 web_service.py &>log.txt &
python3.7 pipeline_http_client.py
一、 docker 服务启动启动
# 开启 docker 自启动
systemctl enable docker.service
# 关闭 docker 自启动
systemctl disable docker.service
二、docker 容器自动启动
# 开启容器自启动
docker update --restart=always 【容器名】
例如:docker update --restart=always tracker
# 关闭容器自启动
docker update --restart=no【容器名】
例如:docker update --restart=no tracker
##### 相关配置解析
no:
不要自动重启容器。(默认)
on-failure:
如果容器由于错误而退出,则重新启动容器,该错误表现为非零退出代码。
always:
如果容器停止,请务必重启容器。如果手动停止,则仅在Docker守护程序重新启动或手动重新启动容器本身时才重新启动。(参见重启政策详情中列出的第二个项目)
unless-stopped:
类似于always,除了当容器停止(手动或其他方式)时,即使在Docker守护程序重新启动后也不会重新启动容器。
三、设置容器内的服务自动启动:
1-首先制作一个启动脚本start_fw.sh
参考
#!/bin/bash
cd PaddleOCR/deploy/pdserving/
nohup python3.7 web_service.py &>log.txt &
/bin/bash
2-将容器制作为镜像,然后启动容器文章来源:https://www.toymoban.com/news/detail-509584.html
sudo nvidia-docker run -it -p 3001:22 -p 2001:1998 -v /home/crnn/OCR_date:/data --entrypoint=/bin/bash --restart=always --name nginx1 -d registry.baidubce.com/paddlepaddle/serving:0.9.2 /home/PaddleOCR/deploy/pdserving/start_fw.sh
3-文章来源地址https://www.toymoban.com/news/detail-509584.html
# 查看所有启动和未启动的容器
docker ps -a
# 获取到容器id, 使用cp命令将容器内的目录拷贝到本地
docker cp containerID:container_path host_path
Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import numpy as np
import requests
import json
import base64
import os
import argparse
parser = argparse.ArgumentParser(description="args for paddleserving")
parser.add_argument("--image_dir", type=str, default="../../doc/imgs/")
args = parser.parse_args()
def cv2_to_base64(image):
return base64.b64encode(image).decode('utf8')
url = "http://127.0.0.1:1998/ocr/prediction"
test_img_dir = args.image_dir
for idx, img_file in enumerate(os.listdir(test_img_dir)):
with open(os.path.join(test_img_dir, img_file), 'rb') as file:
image_data1 = file.read()
# print file name
print('{}{}{}'.format('*' * 10, img_file, '*' * 10))
image = cv2_to_base64(image_data1)
data = {"key": ["image"], "value": [image]}
r = requests.post(url=url, data=json.dumps(data))
result = r.json()
print("erro_no:{}, err_msg:{}".format(result["err_no"], result["err_msg"]))
# check success
if result["err_no"] == 0:
ocr_result = result["value"][0]
try:
for item in eval(ocr_result):
# return transcription and points
print("{}, {}".format(item[0], item[1]))
except Exception as e:
print("No results")
continue
else:
print(
"For details about error message, see PipelineServingLogs/pipeline.log"
)
print("==> total number of test imgs: ", len(os.listdir(test_img_dir)))
到了这里,关于【Ubuntu18.04 docker 启动容器,进入容器,执行脚本】的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!