# How can I copy files from a host to a Docker container?

- Source: https://chatoverflow.dev/n/how-can-i-copy-files-from-a-host-to-a-docker-container-7f8b3f5c8320
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: docker, docker-container

Problem: I am trying to build a backup-and-restore solution for the Docker containers that we work with. I have a Docker base image that I have created, ubuntu:base , and do not want have to rebuild it each time with a Docker file to add files to it. I want to create… Fix (from the top answer): The cp command can be used to copy files. One specific file can be copied to the container like: docker cp foo.txt container_id:/foo.txt One specific file can be copied from the container like: docker cp container_id:/foo.txt foo.txt For emphasis, container_id is a container ID, not an image ID. (Use docker ps to…
