Docker image & login modules - #Ansible 40

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hey hello everyone and welcome in a new video about ansible and in this video number 40 uh about ansible we'll just see how to use a docker login and docker image module and this is a new series series into on sybil playlist at the end of this serie we just will just install docker swam with some service we'll see it in around seven 7 2 7 video so let's go and we just start with some purposes about this tutorial we just want to to learn how to build an image a docker image how to push it on a registry how to log in uh in registry so if you want you can you can follow this link to find some documentation about the docker image module to start i do i just want to have some target server to do it i use a [Music] background file to have some background to to have a virtual machine with background and i just use a background app to have a two server devon's one and advanced two and on this server if i go on it i can go on a defense one for example i have a server with a docker if i run docker case i can see i have no no container and i can use docker images to list all all images present on my server but this is an empty an empty server and we we haven't any image so to start what we want to do we want to create an inventory so i can go i can leave my my server and if i check my background file i can i can get my ip for advanced one on defense 2. i can edit an inventory name zero zero inventory dot ml i'll remove all lines i had a new line named all for all group i had post line to declare all hosts where i want to to work to push my playbook my first one is this one and the second is this one okay um maybe we can just uh run the test with unsymbol dash i my inventory i want to run on all group i just want to run a module with just the the ping module so um yes we just need to remove ssh key chain and f and in my home [Music] i just want to clean my no host [Music] okay and i want to remove with dash air on this one and this one okay i can run again my ping and we just need to use background because this is a virtual server with background we use the user background and we have a password for this user and this password is a background by default okay now we're paying our server we can edit a first playbook [Music] to just install to use [Music] docker module with ansible we need to install uh to install a python 3 dash docker package or with a pip3 we just need to install uh the docker library uh in our case we just use the app module named uh python3 dash docker so to do it i clean my file i edit a name for my playbook my first playbook for example and i want to run on all my target server and i want to add a task on the first task the first task is my installation of my python 3 docker library package and we just want to install [Music] python 3 or docker sdk yes and we want to install it we we want to use apt module the name of our package python 3. occur and we want to update cache [Music] and after it we add valid uh casualty time sorry cash valid time and we set it for one hour and after it we can we need to to add a become because we need to do a sudo to run your our apt command and now we can run our ansible playbook command with dash i our inventory our user background [Music] k and we don't need to use a dash upper key because uh we our background user uh is into our studio with a new password and we just need to set the dash minus k and after it we just want to run our playbook so our password ssh password we run it and it's okay for the docker sdk installation and after it we can we can see some parameters about a docker image docker image of module we can set the api version which which version we want to use with our docker api we have uh build a specific build parameter with many options for example args where you can set some args about this build with a format like a k value the cache the case from if you want to use the source image in cache [Music] the container limits if you want to set a limit for the build container not for the the container after our docker run your when you want to run your your new image this is just the container about the build we can set the number of cpu cpu shares memory max memory we can set the docker file as the name of this docker file if you need you can set a slash atc host about this container this is a specific container for the build http as a network sorry the path the contextual path pool if you want to pull from from with the from instruction in our docker file if you want to remove all intermediate images you can use ram the target of course the final image and some deprecated parameters like your build dogs because our build dogs is similar as uh argon in our build this sales certificate ca certificate client certificate client key the container limit if you want to activate the debug mode where which docker socket do you want to use i have a local socket or remotely socket docker file this is like like the docker file in the build parameter if you want to force to remove an image if that absent if you want to remove an image on your target server you can do it with a state to set to absent and first to yes the first source if you want you can build load pool if the the image already exists first tag and some other options you can we have the name about our image [Music] the pool the push [Music] the repository and some other options very important option uh very important parameter a source you can set source to build load pool or local if you set it to build you use the source to create your image is just the docker file if you want to set a source to load the module use a tar archive to to to pull your image to create your image pull if you want to pull from a registry private or public registry on local if you just want to to do it locally some other option the state very important you want your image just be will be present build or absent to remove it the tag and etc so our first example we just want to pull an image with our module docker image so i copy it i go into my ansible here we can just connect with ssh on our advanced one server i can run docker images we have no image okay and now we just want to edit our playbook and add a new task okay so be careful doing notation [Music] we can remove it like here and what we want to do we want to pull an image on our target servers we have two server we do it on two servers and the name of our image is alpin and with alpine we we use the latest tag and we just need to run again our command our ssh password and in this task we pull image alpine image on our target servers and to see it i just run docker images and now we have one image alpine with tagged set to latest good um a second a second example we want to re-tag to re-tag an image to change the tag and to do it and just edit again our playbook and [Music] i remove some indentation okay right and we run it again and with this task what we do we re-tag we change the tag of our alpine [Music] and change it to another tag the state is present but all of the following are missing source okay [Music] source local okay and we run it again and now if we go on our target server what we have we have uh we we used alpine and re-tag this image to this one my registry one image set with a specific tag and we can see this is the same image id for this one and for this one right and now what we can do we can uh just import an image like a docker import command with a specific file a tar file and to do it i just copy this line and with these lines what we do so i remove it okay and i paste it [Music] and in the first task what we do we we copy a file a local file and on our laptop in slash tmp on target servers and with this image with star format i just want to use it with the source set to load and we load our our file our tar file to define our new image in our docker engine so to do it we need uh we need to to get this file image image the test file so to do it i just copy you can follow the link below the the video and you can find you can find this file in uh ansible directory and the number 40 for our video and we can copy the image tar from it i copy it in the same in the same directory like my playbook and i can run again my playbook i set my password i run the playbook and if we go on so the first task is to copy our image and the second in the second task we will uh create our image in our docker engine so to check it we run together images and we can see now our image named test and the version set to v1 okay another example what we want to do we can create an image from a docker file okay so to do it what we need to do we want to edit our playbook of course i remove all lines okay so i can remove annotation okay in the first task we want to create on our target server a specific directory to build our image in slash tmp we create a directory named build and in second task we want to copy a local directory on our target directory we copy apt directory into tmp build and finally what we do we run docker image module we want to create an image named emg build with a specific tag and we use the parameter source set to build so of course we use the build parameter and specify the path and the path is our new directory the name of our docker file by default docker file and we use a cache from alpine 3.9 okay to do it we need to copy the app directory like the previous playbook we have it in the same directory about our video we have app yes we use dash air and we want to copy it here now we have it locally we have an app with docker file and a requirement this is a simple docker file if we check okay we just use python we install pip some element and we copy the content of our app directory we run requirements and we run our app dot pi okay to do it we run again our command [Music] okay and ansible oh we have an error could not be found slash [Music] you do not have access where is my playbook okay here tmp build up build up here oh maybe just here we set the owner to a background okay so i run it again yes background or password no again requested a build path and not be found maybe we can check slash tmp we have the build directory oh yes of course we can't choose [Music] we can't use the uh here just build not build the path sorry we run it again okay and now we can build okay we can build our new image from our docker file okay oh no search package uh what uh we're already mgm message commander so we can uh right around intermittent container um no search file directory here maybe we can just change the docker file [Music] we can just remove this one and this one just to create a new image to to do a sample sample image so we can run it again yes i don't know maybe yes okay and now we can run again local images right and now we have our emg build and the intermediate image python with a specific tag 3.9 with alpine another example i think we can just we want to push an image on the gitlab registry in our case so to do it i copy [Music] this uh this task i want to edit my playbook i remove hole here yes okay yes we want to yes i remove some annotation i remove it first task we want to run a docker login with a docker login module here we want to connect on the git libraries tray the username xavkey and we want to use a specific token like a password we want to reauthorize a set to yes and after it we want uh to to build an image uh with uh our docker file set uh with the path a local pass with our previous directory and we want to put it and after it what we want to do we want to build it and we set the name of our image and that's all i think so yes it's okay here and of course if we need to connect to our gitlab we need to have a token and we can find this token into our we can edit our profile access token and i want to create a new token i send it to unsybel we want to write into registry and read it and we create personal token i copy it i can just create this is not the good way but i want to to create a group verse [Music] okay directory i add it into group bars or tml file i remove all lines to it okay i want to copy the name of our variable okay voltoku and gitlab i had it like a key in our specific file we'll see in next videos how to use vault to encrypt some file with secret so in our case we don't want to to use it we just want to to to run a secret like a simple variable so now we can run it again here set the password we run it again and now we have the build and if we check on our gitlab here if i go into our so which which project we push it into a gitlab glove key and test the flux project if i go into this project test flux here if i go into registry container registry maybe um oh uh what did we do build a saucer oh which option maybe we need to add an option we want to push it [Music] sorry nope not not this one we want to push oh we need to set it to push i think uh build and we want to push here push set it to yes no [Music] password [Music] okay we run it again oh use proxy and supported parameters okay image push oh no of course yes we want to pull for the create to create it and we want to push push yes it's okay i think we can run it again [Music] we have the local docker login okay it's okay and now we build our image and we want to push it on our container registry that take a few seconds okay and now if we refresh our page okay we have our image and the version seems good i think yes 1.1 and a specific oh we don't define a name i think yes and we by default um by default gitlab add a root image like a name so that's all for today thank you for following this video and i see you in the next video bye
Info
Channel: XavkiEn
Views: 246
Rating: 5 out of 5
Keywords: devops tutorials, devops beginners, learn devops, devops course, ansible docker, docker image, docker push, docker build, ansible docker login
Id: O79Pwy2SEjg
Channel Id: undefined
Length: 31min 45sec (1905 seconds)
Published: Fri Jul 09 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.