Categories
Docker postgres

Postgres docker import data

To load a csv file into a table, one way to do it is to use the docker cp command to copy the file into the container. You can then run the \copy command from a cmd line in the container.

docker cp ./projects.csv  some-postgres:/projects.csv
docker exec -it some-postgres psql -U postgres
** from psql:
postgres=# \copy projects(id,project_name,description) from '/projects.csv' csv header;

Categories
Docker React

Create docker container in Code

remote-containers extension allows you to build and run a docker image of your source.

https://www.youtube.com/watch?v=KFyRLxiRKAc&t=309s

In the devcontainer.json file, add the following 2 lines:
  "forwardPorts": [3000],
  "postCreateCommand": "npm install",

  "containerEnv": {
    "CHOKIDAR_USEPOLLING":"true"
  }
Build Container
F1
remote-containers rebuild and Reopen in containers
go to terminal and npm run start.  This will open the node app on port 3000 in a browser. 

This is definitely a work in progress. watch the video.

Categories
Docker postgres

docker and postgres sql

Back to fedora.  up to 31.
loading a sql file into a docker postgres db from the command line.
(see my github docker-compose for the postgres db setup)
note:
/data/raw is my shared volume with postgres;
some-postgres is the postgres container name
data2.sql is a sql txt file.


sudo docker exec -it  some-postgres psql  -U postgres  -d sqldb -f /data/raw/data2.sql
Categories
Docker Mariadb

mysqlimport

When importing a data file into mysql/mariadb, I found that the below line works:


 docker exec -it some-mariadb mysqlimport -u root -pmy-secret-pw --local --ignore-lines 1 --columns month,day,time,username,ip,port,notes hacktrack  ./data/raw/ssh_failure.tab.txt
Categories
Docker Mariadb

docker mysql load dump file

This is how to load a sql dump file from directory to a mysql database in a container.

Make sure you have a volume set up with the directory you keep your sql files in.  In my case, I have a directory called “/data/raw” that I keep all my csv and sql files in for loading and dumping.

docker command

sudo docker run --name some-mariadb -v /data/mysql:/var/lib/mysql -v/data/raw:/data/raw-e MYSQL_ROOT_PASSWORD=my-secret-pw -d mariadb:latest

or…

docker-compose yaml file.


  mariadb:
    image: mariadb
    container_name: some-mariadb
    environment:
    - "MYSQL_ROOT_PASSWORD:my-secret-pw"
    volumes:
    -  /data/mysql:/var/lib/mysql
    - /data/raw:/data/raw
    ports:
    - 3306:3306

I change the directory to my /data/raw directory on my linux box that I’m running the container on.

To load a file into mysql/mariadb, open mysql from the command line:


docker exec -it  some-mariadb mysql -u root -pmy-secret-pw my-database

 

and then…


MariaDB []> source /data/raw/dump-file_data.sql

 

I use the same method for postgres

Categories
Docker Redis

docker redis

working with redis, I start redis with this command:

docker run --name some-redis -d redis redis-server --appendonly yes

 

to access redis with redis-cli, I use:

docker exec some-redis redis-cli

 

Categories
Docker

Docker

Useful commands
grabs ip address

sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' some-mariadb

Categories
Docker

Docker

 

My most commonly used docker images:
postgres

docker run --name some-postgres -v /data/raw/:/data/raw/ -v /data/postgres:/var/lib/postgresql/data -d postgres

portainer: nice docker web gui.  It includes templates you may dnload without going to command line.

sudo docker volume create portainer_data
sudo docker run -d -p 9000:9000 --name portainer --restart always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer

redis – Started from portainer
rabbitmq – started from portainer