# Ansible as a Docker Container ### Running Ansible inside a Docker container **Docker workflow**  #### Step 1: Install Docker ````go=1 sudo apt-get update sudo apt install docker-ce docker version sudo usermod -aG docker labsuser docker images ```` #### Step 2: Write Dockerfile and create Ansible image ````go=1 vi Dockerfile Dockerfile Content FROM ubuntu:20.04 ENV ANSIBLE_VERSION 2.9.17 RUN apt-get update; \ apt-get install -y gcc python3; \ apt-get install -y python3-pip; \ apt-get clean all RUN pip3 install --upgrade pip; \ pip3 install "ansible==${ANSIBLE_VERSION}"; \ pip3 install ansible ```` #### Step 3: Build the image using the following Docker command ````go=1 docker build -t ansible:latest . ```` :mag: *Note the . (dot) at the end of command which denotes that Dockerfile is in current directory.* #### Step 4: Validate image creation by checking image list ````go=1 docker images or docker image ls ```` #### Step 5: Run Ansible inside a docker container ````go=1 docker run -it ansible ansible --version ```` #### Step 6: [Optional] Push your Ansible image to Docker Hub ````go=1 docker login docker push ansible:latest docker tag ansible sk12k/ansible docker image ls docker push sk12k/ansible ````
×
Sign in
Email
Password
Forgot password
or
Sign in via Google
Sign in via Facebook
Sign in via X(Twitter)
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
Continue with a different method
New to HackMD?
Sign up
By signing in, you agree to our
terms of service
.