This document explains the setup procedure for automatically deploying Docker containers with GitHub Actions.
Table of Contents# Docker Configuration GitHub Actions Configuration Server-Side Configuration Troubleshooting Docker Configuration# Dockerfile (Static Site + nginx)# Generates static HTML and serves it with nginx.
F W C R C R # F # # C C E C R O O U O U R O O X M O R P N P N n O F F P P P D M K Y Y g M o o Y Y O D n n i r r S [ n I p p . p n n n E " o R a m m x g N N - g n d c i u u f i 8 g e / k i r f n x x r n 0 i : a a n u o x t t o x n 2 p g s n r : m . x 2 p e t a 3 2 = c " - * a g s l : : b o , a . l e e p u n l j l n r i d i f " p s e v n o i l - i o r i e u s d / g n n a n t t e e " e t g p r t , e u c A s t / / " S t / a n d a p p g a b t u p i e u i b / n m i c l . x o l i o / n d f c u c e i t o o r l p n f e u f f s t . ; d " p / ] u d b e l f i a c u l / t u . s c r n s f h a r e / n g i n x / h t m l nginx.conf (SPA Configuration)# For SPAs, dynamic routes (/item/:id, etc.) need to fall back to index.html.
s } e r v e l s r i # g g # l } # l } r i e o n z z o o s r o d g i i S c S c { t v t e z p p P a t a e e x i _ A t t a t e a n r / p o t : i r t i x d _ u i n y o y i o p d 8 n s n c ; p f n _ c n i _ 0 a r d o e a f r h ; m / e m s l / i f ~ e e e s x p l l i * s a h . r t b { e l d l a h e e a s e 1 e o r t s x c y r c e m s t k $ c ( ; a / l i / u a j C l n ; o p n r c s a h g n l o i h | c o i a n i c h s n i - $ n s e t x n e u g s - ; / x r | C h t i i p o t e s / n n m x t g t l t e / | r ; / n i j o c t n p l s d g s p e | " a x j p a t . p u p h h e b p s t g l l m | i i t l g c c o ; i , a f t i | i i n i m o d c m n e o u / x | t j . s a s h v b o t g l n m | e l w " a o ; p f p f l | i w c o a f t f i 2 o ) n $ / j { a v a s c r i p t t e x t / x m l a p p l i c a t i o n / x m l a p p l i c a t i o n / x m l + r s s t e x t / j a v a s c r i p t ; docker-compose-prod.yml (Traefik Integration)# s n e e r c t t v j w r i _ b l n r p o a e c f u a e e o r e x e r i c b t t t t t t t - s r - k f t s o l o e r r r r r r w t t s i e : n d n l a a a a a a o t a s " : k r t : t s e e e e e e r r r : 8 - n : e : f f f f f f k a t 0 n a x i i i i i i s e : 0 e l t k k k k k k : f 3 t : : . . . . . . i a : w e h h h h h k l 8 o t . n t t t t t - w 0 r r a t t t t t n a " k u b p p p p p e y : e l . . . . . t s e r r r r m w : o o o o i o u u u u d r t t t t t d k r e e e e l u r r r r e e s s s s w . . . . a c c c c r j j j j e _ _ _ _ s f f f f . r r r r g o o o o z n n n n i t t t t p . . . . - r e t m c u n l i o l t s d m e r . d p : y c l r p e e e H o r w s o i t a s s n r r . t t e e c ( s s s o ` : o : m y l p o w v g r u e e z e r b r i s - s : p s d e - : o c m c m u y o t a r r m r i e e p u n s r e . o e c l s o v s m e ` r )
GitHub Actions Configuration# .github/workflows/prod.yml# n o c j a n o o m : p w r n g c b b e u o e c r a s u : s b r p t u o n : i r s h r k o y r u c l u t p : a f s p r p e d n e - r n l i e e : l _ s p o c o t s n - a - s n u w d h w o : c ' i n o : a s i e _ r y p n d n m e t h u k p s s d y [ : a - _ : e s h o s e o c : i _ w g p d : : : s e y r r s c g d d d d s d e e r e u t r : t i e d i o o o o [ p i b s o p b D a : n : p t t c c c c ' a s h ' g l u e p a $ t / k k k k m t p o r o n p p $ m { $ : - h p e e e e a c a o e y t l l { e { { e o u r r r r s h t k s : u o e { : { | m l t : c ] s - y b s e l c c c s e h : l o s $ e s / o o o y r : a D y e { c e $ m m m s ' t t o / c { r c { p p p t ] r e c s r e r { o o o e u s k s e s t e s s s m e t e h t e s t s e e e r - s c . s e p a . r R . c - - - r C c R e E R r f f f u o t E t M E e n n i M s O M t d d d e t o O . T O s o o o a n T R E T . c c c - i @ E E _ E R k k k a n m _ M K _ E e e e e a H O E P M r r r r s O T Y O O - - - t S E R T c c c e T _ } T E o o o o r U } _ m m m l } S } U p p p u } E } S o o o m R E s s s e R e e e s } - - - } } p p p - } r r r f / o o o c d d d j . . . _ y y y f m m m r l l l o n b d u t u o p i w l n - d d Registering GitHub Secrets# Register using GitHub CLI:
g g g g h h h h s s s s e e e e c c c c r r r r e e e e t t t t s s s s e e e e t t t t R R R R E E E E M M M M O O O O T T T T E E E E _ _ _ _ H U P K O S O E S E R Y T R T < - - - ~ b b b o o . d d d s y y y s h " " " / x u 2 y x s 2 o x e " u . r r x n _ x a k x m e . e y x " / x i x d . _ x r x s x a " Or from the GitHub Web UI:
Settings -> Secrets and variables -> Actions -> New repository secret
Secret Name Description REMOTE_HOSTServer IP address REMOTE_USERSSH username REMOTE_KEYSSH private key (full text) REMOTE_PORTSSH port (usually 22)
Server-Side Configuration# 1. Clone the Repository# c g d i t / h c o l m o e n / e u s g e i r t n @ a g m i e t h u b . c o m : y o u r - o r g / y o u r - r e p o . g i t c j _ f r o n t
HTTPS format causes authentication errors when git pull is run from GitHub Actions.
c g d i t / h r o e m m e t u e s e s r e n t a - m u e r / l c j o _ r f i r g o i n n t g i t @ g i t h u b . c o m : y o u r - o r g / y o u r - r e p o . g i t 3. Add GitHub’s Host Key# s s h - k e y s c a n g i t h u b . c o m ~ / . s s h / k n o w n _ h o s t s 4. Register SSH Public Key with GitHub# Check the server’s public key:
c a t ~ / . s s h / i d _ r s a . p u b
If no key exists, generate one:
s s h - k e y g e n - t r s a - b 4 0 9 6 - C " y o u r - e m a i l @ e x a m p l e . c o m "
Register the public key with GitHub:
Account level (recommended): GitHub -> Settings -> SSH and GPG keys -> New SSH keyRepository level : Repository -> Settings -> Deploy keys -> Add deploy keyNote : The same SSH key can only be registered for one repository or one account on GitHub. If you need to use it across multiple repositories, register it at the account level.
5. Creating docker-compose-prod.yml# s } e r v e l s r i # g g # l } # l } r i e o n z z o o s r o d g i i S c S c { t v t e z p p P a t a e e x i _ A t t a t e a n r / p o t : i r t i x d _ u i n y o y i o p d 8 n s n c ; p f n _ c n i _ 0 a r d o e a f r h ; m / e m s l / i f ~ e e e s x p l l i * s a h . r t b { e l d l a h e e a s e 1 e o r t s x c y r c e m s t k $ c ( ; a / l i / u a j C l n ; o p n r c s a h g n l o i h | c o i a n i c h s n i - $ n s e t x n e u g s - ; / x r | C h t i i p o t e s / n n m x t g t l t e / | r ; / n i j o c t n p l s d g s p e | " a x j p a t . p u p h h e b p s t g l l m | i i t l g c c o ; i , a f t i | i i n i m o d c m n e o u / x | t j . s a s h v b o t g l n m | e l w " a o ; p f p f l | i w c o a f t f i 2 o ) n $ / j { a v a s c r i p t t e x t / x m l a p p l i c a t i o n / x m l a p p l i c a t i o n / x m l + r s s t e x t / j a v a s c r i p t ; 0
Troubleshooting# nginx 404 Error (SPA)# If you get a 404 when accessing dynamic routes (/item/:id), add the following to nginx.conf:
s } e r v e l s r i # g g # l } # l } r i e o n z z o o s r o d g i i S c S c { t v t e z p p P a t a e e x i _ A t t a t e a n r / p o t : i r t i x d _ u i n y o y i o p d 8 n s n c ; p f n _ c n i _ 0 a r d o e a f r h ; m / e m s l / i f ~ e e e s x p l l i * s a h . r t b { e l d l a h e e a s e 1 e o r t s x c y r c e m s t k $ c ( ; a / l i / u a j C l n ; o p n r c s a h g n l o i h | c o i a n i c h s n i - $ n s e t x n e u g s - ; / x r | C h t i i p o t e s / n n m x t g t l t e / | r ; / n i j o c t n p l s d g s p e | " a x j p a t . p u p h h e b p s t g l l m | i i t l g c c o ; i , a f t i | i i n i m o d c m n e o u / x | t j . s a s h v b o t g l n m | e l w " a o ; p f p f l | i w c o a f t f i 2 o ) n $ / j { a v a s c r i p t t e x t / x m l a p p l i c a t i o n / x m l a p p l i c a t i o n / x m l + r s s t e x t / j a v a s c r i p t ; 1
git pull Error in GitHub Actions# Error : fatal: could not read Username for 'https://github.com'
Cause : Repository was cloned in HTTPS format
Solution : Change to SSH format
s } e r v e l s r i # g g # l } # l } r i e o n z z o o s r o d g i i S c S c { t v t e z p p P a t a e e x i _ A t t a t e a n r / p o t : i r t i x d _ u i n y o y i o p d 8 n s n c ; p f n _ c n i _ 0 a r d o e a f r h ; m / e m s l / i f ~ e e e s x p l l i * s a h . r t b { e l d l a h e e a s e 1 e o r t s x c y r c e m s t k $ c ( ; a / l i / u a j C l n ; o p n r c s a h g n l o i h | c o i a n i c h s n i - $ n s e t x n e u g s - ; / x r | C h t i i p o t e s / n n m x t g t l t e / | r ; / n i j o c t n p l s d g s p e | " a x j p a t . p u p h h e b p s t g l l m | i i t l g c c o ; i , a f t i | i i n i m o d c m n e o u / x | t j . s a s h v b o t g l n m | e l w " a o ; p f p f l | i w c o a f t f i 2 o ) n $ / j { a v a s c r i p t t e x t / x m l a p p l i c a t i o n / x m l a p p l i c a t i o n / x m l + r s s t e x t / j a v a s c r i p t ; 2
Error : Host key verification failed
Solution : Add GitHub’s host key
s } e r v e l s r i # g g # l } # l } r i e o n z z o o s r o d g i i S c S c { t v t e z p p P a t a e e x i _ A t t a t e a n r / p o t : i r t i x d _ u i n y o y i o p d 8 n s n c ; p f n _ c n i _ 0 a r d o e a f r h ; m / e m s l / i f ~ e e e s x p l l i * s a h . r t b { e l d l a h e e a s e 1 e o r t s x c y r c e m s t k $ c ( ; a / l i / u a j C l n ; o p n r c s a h g n l o i h | c o i a n i c h s n i - $ n s e t x n e u g s - ; / x r | C h t i i p o t e s / n n m x t g t l t e / | r ; / n i j o c t n p l s d g s p e | " a x j p a t . p u p h h e b p s t g l l m | i i t l g c c o ; i , a f t i | i i n i m o d c m n e o u / x | t j . s a s h v b o t g l n m | e l w " a o ; p f p f l | i w c o a f t f i 2 o ) n $ / j { a v a s c r i p t t e x t / x m l a p p l i c a t i o n / x m l a p p l i c a t i o n / x m l + r s s t e x t / j a v a s c r i p t ; 3
Error : Permission denied (publickey)
Solution : Register the server’s SSH public key with GitHub
References#