Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How do I copy files in a Docker container?

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Before we begin

A project container needs to add a wkhtmltopdf package to handle the conversion between html and pdf files. Because the default apt source server is abroad, the download speed of installing wkhtmltopdf using apt is only a few kb/s.

We need to change a domestic apt image address, such as using Aliyun, NetEyun, and other open source mirror stations. The debain or ubuntu system apt repository configuration is saved in the / etc/apt/sources.list configuration file, which we can replace in the container.

Environment description container image: php:5.6-fpm container system: debian 8 (jessie) configuration file: / etc/apt/sources.listDocker host: Ubuntu Server 16.04. name a chestnut.

1 create a sources.list file with the following contents:

Cat sources.listdeb http://mirrors.aliyun.com/debian/ jessie main non-free contribdeb http://mirrors.aliyun.com/debian/ jessie-proposed-updates main non-free contribdeb-src http://mirrors.aliyun.com/debian/ jessie main non-free contribdeb-src http://mirrors.aliyun.com/debian/ jessie-proposed-updates main non-free contrib

2 back up the files in the container

Docker cp crm-test:/etc/apt/sources.list / tmp/sources.list.bak

This command will copy the sources.list file in the container to the / tmp/ directory on the host

3 replace the sources.list file in the container

Docker cp sources.list crm-test:/etc/apt/sources.list

Instead, this command will copy the files on the host to the container

4 Verification

Docker exec-ti crm-test apt-get updateIgn http://mirrors.aliyun.com jessie InRelease omitted... Fetched 22.0 MB in 19s (1120 kB/s) Reading package lists... Done

5 extended Dockerfile

It is troublesome to add sources.list files to the container every time. We can optimize this step by defining this step in Dockerfile, for example:

Head-N7 php/base/5.6/Dockerfile # php-fpm:5.6FROM php:5.6-fpmMAINTAINER dongnan# aptCOPY conf/sources.list / etc/apt/sources.list command help docker cp-- helpUsage: docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH |-docker cp [OPTIONS] SRC_PATH |-CONTAINER:DEST_PATHCopy files/folders between a container and the local filesystemOptions:-a,-- archive Archive mode (copy all uid/gid information)-L -- follow-link Always follow symbol link in SRC_PATH Summary

Finally, let's summarize the knowledge points in the article.

The docker CP subcommand can be used to copy files between the container and the host. If you are not prompted to copy the file, the destination file will be replaced directly. Please do the backup work in advance. For the container's sources.list file, you can customize the docker image.

Reference article

Doker&k8s Qun [703906133]

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report