How to have tabcompletion for docker cp? - autocomplete

I want to copy some files from my docker container to my host system using
docker cp container_id:/path/to/file/that/is/annoyingly/long/poit.foo ~/local/
I really would like there to be tabcompletion for the path. Is there a way to achieve it?

Related

Docker Postgres data host volume mapping

I'm trying to docker-containerize PostgreSQL server and this container will have many other applications as well. The need is that, PostgreSQL server data should be mapped to the host volume so that when container is stopped, we won't lose the data. Also that, the next time when we start the container, the same directory can be mapped again and postgres can use the old data. Below is the DOCKERFILE. Note that I'm using ubuntu 22.04 on the host.
FROM ubuntu:22.04
ENV DEBIAN_FRONTEND noninteractive
RUN apt install -y postgresql
ENTRYPOINT ["tail", "-f", "/dev/null"]
Docker image is built using the command
docker build -t pg_test .
and the container is run using the command
docker run --name test -v /home/me/data:/var/lib/postgresql/14/main pg_test
'/home/me/data' is the host directory which is empty where I want to map the postgres server data. '/var/lib/postgresql/14/main' is the directory inside the docker container where the postgres is supposed to store the data.
Once the docker container starts, I enter the docker container using the command
docker exec -it test bash
and once I'm inside, I'm trying to start the PostgreSQL service. But PostgreSQL fails to start as there is no data in '/var/lib/postgresql/14/main' directory. I understand that since I have mapped an empty host directory to '/var/lib/postgresql/14/main' directory, postgres doesn't have the files required to start.
I understand that I'm doing it the wrong way, but I couldn't find a way around it. Can anyone please help me to do this the right way, if there is one?
Any help would be appreciable.
You should use the postgres docker image, it will set up the db for you when you start the container, you can find instructions on https://hub.docker.com/_/postgres
If you must use a custom image, you will need to initialize the db yourself, usually by running initdb or whatever your system provides.
But really you should use the appropriate docker image, and if you need more services you start them in their own container and connect them to the postgres one

Creating Docker Image from Dockerfile

I need to create a docker image with a Dockerfile which is available on a remote computer.
will the below work in Powershell ?
docker build -t MyFirstDockerImage -f //RemoteServerpath/FolderStructure/ .
The docker build can only read local files. But not the remote files. i.e Files should be copied on to the machine where docker build is being executed.

docker postgres, fail to map volume in windows

I wish to store my persists data in my local D:\dockerData\postgres9.6. Below is my docker command
docker pull postgres
docker run -d -v /d/dockerData/postgres9.6:/var/lib/postgresql/data -p 5432:5432 postgres
It successful create a container and I can use pgAdmin to access and create database.
But I found out that there is no file in my D:\dockerData\postgres9.6. I exec bash into the container, there is at least 20+ files inside /var/lib/postgresql/data.
Anyone can point out which part goes wrong?
It depends what kind of Docker you are using on Windows:
Docker Toolbox with VirtualBox: only C:\Users\mylogin is shared by default. D:\ is not mounted.
Docker for Windows with HyperV: only C:\ is mounted by default. Make sure D:\ is a shared drive: see image

Adding a directory from the host filesystem to the docker filesystem (not in a dockerfile)

I have a docker image already. I want to be able to add a directory from the host file system to the docker filesystem. I know that if I am using a base image, I could use the ADD command in the dockerfile but I am not actually using a base image, I want to build a new docker image based on my image with some directories added to it from my host file system. Is there a way to do that?
Just create another docker image based your image.
FROM base-image-name
ADD host_dir /destination_dir
You do not need a new image, just run it like this:
docker run your_image -v host_dir:local_dir

How import file from computer to docker containers with mongodb

I have a problem with my docker container. I need to import data, something like .csv file from my computer to docker container, but I don't know how. I found a command like "docker insert" but it doesn't work.
You can do this using Docker volumes.
docker run -i -t -v /home/user/stuff:/data ubuntu /bin/bash
Where in this example /home/user/stuff is a directory OUTSIDE the container and /data is the directory where that content will be located INSIDE the container.