Difference between revisions of "Docker"
(8 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
== Docker File == | == Docker File == | ||
+ | '''ARG''' | ||
+ | These are arguments that can be used in side the docker file. | ||
+ | ARG BASE_DIR=/opt/app | ||
+ | ... | ||
+ | COPY ./file.txt $BASE_DIR | ||
+ | |||
+ | '''Port''' | ||
+ | To expose port to docker to be exposed, lol kind of redundant. | ||
+ | EXPOSE 4000 | ||
== Docker Images == | == Docker Images == | ||
Line 17: | Line 26: | ||
docker rmi -f {imagename}:{tag} | docker rmi -f {imagename}:{tag} | ||
− | + | '''Run''' | |
+ | The big difference between run and start. Run will create a container and then start it. Where start just starts up a container. | ||
+ | |||
This is how you run an image | This is how you run an image | ||
docker run -it {imagename}:{tag} | docker run -it {imagename}:{tag} | ||
− | To open the ports | + | Add environment variables to the container. |
+ | docker run -it -e USERNAME='jdoe' {imagename}:{tag} | ||
+ | |||
+ | To open the ports. Make sure you do this and have the ports exposed in your Dockerfile. | ||
docker run -p 8080:8080 -it {imagename}:{tag} | docker run -p 8080:8080 -it {imagename}:{tag} | ||
Line 32: | Line 46: | ||
To get into bash for a container. | To get into bash for a container. | ||
docker exec -it <container id> /bin/bash | docker exec -it <container id> /bin/bash | ||
+ | |||
+ | To see a list of running containers | ||
+ | docker ps | ||
+ | |||
+ | To see a list of containers running or stopped | ||
+ | docker ps -a | ||
+ | |||
+ | '''Import Image''' | ||
+ | To import an image that built by buildah in to docker. | ||
+ | docker load -i image-buildah.tar | ||
+ | |||
+ | '''Modify Image Tages''' | ||
+ | This will change the tag for an image. | ||
+ | docker tag 304cf8d51e52 cs:latest | ||
+ | |||
+ | == Docker Build Image == | ||
+ | When you have a Dockerfile you want to build use the following command. | ||
+ | |||
+ | docker build -t myimage . | ||
+ | |||
+ | == Docker QuickStart Terminal == | ||
+ | When using the QuickStart terminal, it creates a virtual machine to run docker in. | ||
+ | |||
+ | To get to this machine. | ||
+ | docker-machine ssh default | ||
+ | |||
+ | A directory with persistent storage each time the machine starts up. | ||
+ | /var/lib/boot2docker/ | ||
+ | |||
+ | To create a startup scrip when the machine starts up. Create this file '''/var/lib/boot2docker/bootlocal.sh''' with execution permissions. | ||
+ | |||
+ | Tip: To sudo when in the machine | ||
+ | sudo -s | ||
+ | |||
+ | |||
+ | I had an issue with an invalid ssl cert. To fix the issue you must have the docker-machine load a file called daemon.json and inside the file you add untrusted URL sources. | ||
+ | |||
+ | 1. Log in to the docker-machine | ||
+ | docker-machine ssh default | ||
+ | |||
+ | sudo -s | ||
+ | |||
+ | 3. Change directories to the persistent storage directory. | ||
+ | cd /var/lib/boot2docker/ | ||
+ | |||
+ | 4. Create the daemon.json file. | ||
+ | { | ||
+ | "insecure-registries" : ["myregistrydomain.com:5000"] | ||
+ | } | ||
+ | |||
+ | 5. Create a boot script for the docker machine | ||
+ | touch /var/lib/boot2docker/bootlocal.sh && chmod +x /var/lib/boot2docker/bootlocal.sh | ||
+ | |||
+ | 6. Edit the file and copy the daemon.json file to the correct location. | ||
+ | #!/bin/sh | ||
+ | cp /var/lib/boot2docker/daemon.json /etc/docker/daemon.json | ||
+ | |||
+ | 7. Exit the docker-machine | ||
+ | |||
+ | 8. Restart the docker machine | ||
+ | docker-machine restart |
Latest revision as of 08:41, 11 April 2022
This is a page all about Docker and helpful commands.
Docker File
ARG These are arguments that can be used in side the docker file.
ARG BASE_DIR=/opt/app ... COPY ./file.txt $BASE_DIR
Port To expose port to docker to be exposed, lol kind of redundant.
EXPOSE 4000
Docker Images
List This will show a list of all docker images.
docker images
Remove This will remove an image from the list.
docker rmi {imagename}:{tag}
You might need to force it.
docker rmi -f {imagename}:{tag}
Run The big difference between run and start. Run will create a container and then start it. Where start just starts up a container.
This is how you run an image
docker run -it {imagename}:{tag}
Add environment variables to the container.
docker run -it -e USERNAME='jdoe' {imagename}:{tag}
To open the ports. Make sure you do this and have the ports exposed in your Dockerfile.
docker run -p 8080:8080 -it {imagename}:{tag}
To run the image in a detacted container for it run in the background.
docker run -d -it {imagename}:{tag}
To run an image and go right into bash for the starting point.
docker run -it --entrypoint "/bin/bash" {imagename}:{tag}
To get into bash for a container.
docker exec -it <container id> /bin/bash
To see a list of running containers
docker ps
To see a list of containers running or stopped
docker ps -a
Import Image To import an image that built by buildah in to docker.
docker load -i image-buildah.tar
Modify Image Tages This will change the tag for an image.
docker tag 304cf8d51e52 cs:latest
Docker Build Image
When you have a Dockerfile you want to build use the following command.
docker build -t myimage .
Docker QuickStart Terminal
When using the QuickStart terminal, it creates a virtual machine to run docker in.
To get to this machine.
docker-machine ssh default
A directory with persistent storage each time the machine starts up.
/var/lib/boot2docker/
To create a startup scrip when the machine starts up. Create this file /var/lib/boot2docker/bootlocal.sh with execution permissions.
Tip: To sudo when in the machine
sudo -s
I had an issue with an invalid ssl cert. To fix the issue you must have the docker-machine load a file called daemon.json and inside the file you add untrusted URL sources.
1. Log in to the docker-machine
docker-machine ssh default
sudo -s
3. Change directories to the persistent storage directory.
cd /var/lib/boot2docker/
4. Create the daemon.json file.
{ "insecure-registries" : ["myregistrydomain.com:5000"] }
5. Create a boot script for the docker machine
touch /var/lib/boot2docker/bootlocal.sh && chmod +x /var/lib/boot2docker/bootlocal.sh
6. Edit the file and copy the daemon.json file to the correct location.
#!/bin/sh cp /var/lib/boot2docker/daemon.json /etc/docker/daemon.json
7. Exit the docker-machine
8. Restart the docker machine
docker-machine restart