0% found this document useful (0 votes)
81 views

Docker

1. The document discusses various Docker commands for pulling, running, and managing Docker images and containers. It covers starting and stopping containers, viewing container lists, removing containers and images, mapping volumes, and setting environment variables and ports. 2. Networking between containers using links, custom networks, and exposing ports is explained. Persisting data using volumes is also summarized. 3. The end of the document discusses Dockerfile usage and building images from Dockerfiles to run Node.js applications using Ubuntu images. It also covers Docker commands for cleaning up containers and images.

Uploaded by

Muhammet Kose
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views

Docker

1. The document discusses various Docker commands for pulling, running, and managing Docker images and containers. It covers starting and stopping containers, viewing container lists, removing containers and images, mapping volumes, and setting environment variables and ports. 2. Networking between containers using links, custom networks, and exposing ports is explained. Persisting data using volumes is also summarized. 3. The end of the document discusses Dockerfile usage and building images from Dockerfiles to run Node.js applications using Ubuntu images. It also covers Docker commands for cleaning up containers and images.

Uploaded by

Muhammet Kose
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

docker pull mongo

docker images
docker run redis
docker run ubuntu sleep 3 (start running and stop after 3seconds later)
docker run -it ubuntu (you entered on ubuntu) -it means interactive terminal
ls
cd etc
clear
cat os-release
exit (close or down)
docker run mongo ( to close it enter control and C for mongo closing)

docker run -it ubuntu


docker ps( shows up images)
docker ps -a
or docker ps -all (shows past run images)
ps -ef (shows running processes on pc)
docker container ls (shows Active container's list)
docker container ls -a (shows all containers)
docker run -it --name bash_ubuntu ubuntu (changes name of container)
docker start container_name (run on backround)
docker stop container_name
docker run -it ubuntu (start with new name,create new instance)
docker stop 'container id' ( container characters till determination from others')
docker rm containerid or container name (to remove from docker ps -all)
docker rm 03 bf 2d... (multiple selections remove)
docker container rm $(docker container ls -aq) removes all
docker run redis:5 downloads and runs version 5 of redis,tag
docker image tag ubuntu _name changes repository name of image
docker run -it changed_image_name
docker run -d redis works in detach mode in backround
docker attach container_id_of_redis runs in attach mode in terminal blocking,
docker container logs container_id or repository_name shows logs of detach mode's
container
docker run image_id or image_name
docker run -it image_id or image_name runs with interactive terminal for
entering,replying data
docker run -p external_port_number:internal_port_number image_name sets both port
numbers
docker run -p 3000:3000 -d image_name_or_id runs in detach mode
docker run -p 3002:3000 -d image_name_or_id
docker run -p 3003:3000 -d image_name_or_id

Docker Host üzerinde containerler "Stateless" olarak çalışırlar.Yani herhangi bir


bilgi içerlerinde kayıt edilmez.

Container stop edildiğinde, kayıt edilen bilgiler sonsuza kadar silinir.


Bu sorunu ortadan kaldırmak için 'Volume' kullanılır.
Bunu yapmak için; Container'ı up yaptığımızda ,kayıt edilecek klosörün Docker Host
üzerindeki adresini belirtiriz. 'Volume Mapping'
Böylece container içerisinde bir veri yazıldığında,Docker Engine bunu alır bizim
volume mapping yaptığımız klasörün içerisine aktarır.
Böylece container start/stop edildiğinde yazılan bilgiler docker host üzerinde
kalmaya devam eder.

docker run mongo (stateless)


docker stop mongo (no saved data)
docker run -v /opt/data:/data/db mongo (destination : source on host ) volume
mapping

docker run -v /opt/data:/data/db -p 27017:27017 -d mongo

destination on host : settings, resources, file sharing ,Destination file should be


there!

docker inspect image_name_orid shows all info about image

docker inspect container_name_orid

container is up version or instance of a image

docker run e- MYSQL_ROOT_PASSWORD=test123 -d mysql (-e refers env,enviromental


variable)

docker image ls

docker -v

sudo docker pull --platform linux/amd64 mysql

sudo docker run --platform linux/amd64 mysql

docker pull phpmyadmin/phpmyadmin (phpmyadmin/phpmyadmin cuz It's not verified


publisher in docker, we should write it with user name or id and
/products,process..app

connection between phpmyadmin and mysql can be with 'docker compose',link ,and
network

docker container ls -a

docker run --name phpmyadmin -p 8000:80 --link mysql-server(image name of


connection):db(alliance like localhost) -d phpmyadmin

***docker run --name mysql-server -p 3306:3306 -v


/Users/muhammetkose/Documents/Opt/Data:/etc/mysql/conf.d -e
MYSQL_ROOT_PASSWORD=test123 --platform linux/amd64 -d mysql

docker stop//start mysql-server (If you forgat -d)

docker run --name pmyadmin -p 8000:80 --link mysql-server:db -d phpmyadmin

docker stop pmyadmin mysql-server

docker start mysql-server

docker start pmyadmin

docker rm container id of mysql-server and pmyadmin : if you removed container,all


tables data wiil be romoved too!
docker run --name PostgreSQL -p 5432:5432 -v
/Users/muhammetkose/Documents/Opt/Data:/etc/postgresql/postgresql.conf -e
POSTGRES_PASSWORD=123456 -d postgres

docker run -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=123456" --name MsSqlServer -p


1433:1433 -v /Users/muhammetkose/Projects/MyFinalProject/SqlServerVolume:/var/opt/
mssql -d mcr.microsoft.com/mssql/server:2019-CU15-ubuntu-20.04

***docker run -e 'ACCEPT_EULA=1' -e 'MSSQL_SA_PASSWORD=Muhammet123456@' -e


'MSSQL_PID=Developer' -e 'MSSQL_USER=SA' -p 1433:1433 -v
/Users/muhammetkose/Projects/MyFinalProject/SqlServerVolume:/var/opt/mssql --name
sql -d mcr.microsoft.com/azure-sql-edge

***protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)


{
optionsBuilder.UseSqlServer(@"Server=127.0.0.1,1433; Database=Northwind;
User=SA; Password=Muhammet123456@");
}

***protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)


{
optionsBuilder.UseSqlServer(@"Server=localhost,1433; Database=Northwind;
User=SA; Password=Muhammet123456@");
}

(terminal within in ECommerceAPI.Persistence)


dotnet ef migrations add mig_1
dotnet ef database update
dotnet ef database drop
(with Package Manager Console in ECommerceAPI.Persistence)
add-migration mig_1
update-database

----------------------------------------------------------------------
DOCKER NETWORK KKINDS

1-)Bridge ,2-)None ,3-)Host 4-) User defined

docker run mongo (automatically creates bridge network)


docker run mongo --network=none (It's none network)
docker run mongo --network=host(It's host network)

docker network create --driver bridge --subnet 182.18.0.0/16 --gateway 182.18.01


todo-app-network

docker network ls or list

TO REMOVE CONTAINER:docker rm Container_Id_or_Name


TO REMOVE IMAGE: docker rmi image_name
TO REMOVE NETWORK: docker network rm network_name_orid

--link containerName:alias

docker does not support static ip for containers.Because of this, we name


containers and we use names for connections.
docker inspect bridge

docker network create --driver bridge --subnet 182.18.0.1/24 --gateway 182.18.0.1


custom-network

docker run --name mongo-server --net custom-network -d mongo

docker ps

docker run --net custom network -p 3000:3000 gkandemir/todo-app


(link ile de yapabilirdik, mongo-server yazdığımız yerde aliası da tanımlamalıyız)

todo
save()
then((savedTodo))=>res.status(200).json(savedToDo))
catch((e)=>res.status(400).json(e));

app.listen(PORT,async()=>{
console.log("sunucu çalışıyor mongo db baglanacak..");
await Mongose.connect("mongodb://mongo-server(container name in
docker):27017/todos",{
useNewUrlParser:true,
useUnifiedTopology:true,
});
console.log.("mongodb'ye bağlandı");
});

docker pull ubuntu:18.04


docker images
docker run -it ubunru:18.04
apt-get update (updates ubuntu)
apt-get install curl-y
curl -sL https://deb.nodesource.com/setup_10.x | bash
apt-get install nodejs -y

ls
cd opt
mkdir node-app
cd node-app

echo 'console.log("nodejsapp from ubuntu..");' >index.js


history

docker container prune :deletes all containers.

You might also like